11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <string> 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <vector> 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/compiler_specific.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/app_sync_bundle.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/extension_prefs.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/extension_sync_bundle.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/pending_enables.h" 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "components/browser_context_keyed_service/browser_context_keyed_service.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h" 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "sync/api/string_ordinal.h" 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "sync/api/sync_change.h" 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "sync/api/syncable_service.h" 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class ExtensionErrorUI; 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class ExtensionSyncData; 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class Profile; 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace base { 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class SequencedTaskRunner; 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace extensions { 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class AppSyncData; 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class ExtensionPrefs; 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class ExtensionSyncData; 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace extensions 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace syncer { 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class SyncErrorFactory; 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class ExtensionSyncService : public syncer::SyncableService, 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public BrowserContextKeyedService { 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ExtensionSyncService(Profile* profile, 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::ExtensionPrefs* extension_prefs, 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ExtensionService* extension_service); 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~ExtensionSyncService(); 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Convenience function to get the ExtensionSyncService for a Profile. 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) static ExtensionSyncService* Get(Profile* profile); 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::ExtensionPrefs& extension_prefs() const { 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return *extension_prefs_; 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Notifies Sync (if needed) of a newly-installed extension or a change to 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // an existing extension. 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void SyncExtensionChangeIfNeeded( 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension& extension); 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // syncer::SyncableService implementation. 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual syncer::SyncMergeResult MergeDataAndStartSyncing( 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) syncer::ModelType type, 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const syncer::SyncDataList& initial_sync_data, 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void StopSyncing(syncer::ModelType type) OVERRIDE; 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual syncer::SyncDataList GetAllSyncData( 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) syncer::ModelType type) const OVERRIDE; 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual syncer::SyncError ProcessSyncChanges( 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const tracked_objects::Location& from_here, 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const syncer::SyncChangeList& change_list) OVERRIDE; 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Gets the sync data for the given extension, assuming that the extension is 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // syncable. 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::ExtensionSyncData GetExtensionSyncData( 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension& extension) const; 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Gets the sync data for the given app, assuming that the app is 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // syncable. 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::AppSyncData GetAppSyncData( 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension& extension) const; 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Gets the ExtensionSyncData for all extensions. 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::vector<extensions::ExtensionSyncData> GetExtensionSyncDataList() const; 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Gets the AppSyncData for all extensions. 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::vector<extensions::AppSyncData> GetAppSyncDataList() const; 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Applies the change specified passed in by either ExtensionSyncData or 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // AppSyncData to the current system. 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns false if the changes were not completely applied and were added 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // to the pending list to be tried again. 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool ProcessExtensionSyncData( 951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::ExtensionSyncData& extension_sync_data); 961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool ProcessAppSyncData(const extensions::AppSyncData& app_sync_data); 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) syncer::SyncChange PrepareToSyncUninstallExtension( 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::Extension* extension, 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool extensions_ready); 1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ProcessSyncUninstallExtension(const std::string& extension_id, 1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const syncer::SyncChange& sync_change); 1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SyncEnableExtension(const extensions::Extension& extension); 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SyncDisableExtension(const extensions::Extension& extension); 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SyncOrderingChange(const std::string& extension_id); 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // |flare| provides a StartSyncFlare to the SyncableService. See 1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // sync_start_util for more. 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetSyncStartFlare(const syncer::SyncableService::StartSyncFlare& flare); 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Return true if the sync type of |extension| matches |type|. 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool IsCorrectSyncType(const extensions::Extension& extension, 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) syncer::ModelType type) 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const; 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Whether the given extension has been enabled before sync has started. 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool IsPendingEnable(const std::string& extension_id) const; 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Handles setting the extension specific values in |extension_sync_data| to 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the current system. 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns false if the changes were not completely applied and need to be 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // tried again later. 1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool ProcessExtensionSyncDataHelper( 1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const extensions::ExtensionSyncData& extension_sync_data, 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) syncer::ModelType type); 1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The normal profile associated with this ExtensionService. 1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Profile* profile_; 1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Preferences for the owning profile. 1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::ExtensionPrefs* extension_prefs_; 1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ExtensionService* extension_service_; 1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::AppSyncBundle app_sync_bundle_; 1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::ExtensionSyncBundle extension_sync_bundle_; 1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set of extensions/apps that have been enabled before sync has started. 1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::PendingEnables pending_app_enables_; 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) extensions::PendingEnables pending_extension_enables_; 1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<ExtensionErrorUI> extension_error_ui_; 1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Sequenced task runner for extension related file operations. 1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Run()ning tells sync to try and start soon, because syncable changes 1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // have started happening. It will cause sync to call us back 1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // asynchronously via MergeDataAndStartSyncing as soon as possible. 1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) syncer::SyncableService::StartSyncFlare flare_; 1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ExtensionSyncService); 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYNC_SERVICE_H_ 158