1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_EXTENSIONS_PENDING_ENABLES_H_ 6#define CHROME_BROWSER_EXTENSIONS_PENDING_ENABLES_H_ 7 8#include <set> 9 10// Included for syncer::ModelType, which is in 11// sync/internal_api/public/base/model_type.h but that is disallowed by 12// chrome/browser/DEPS. 13#include "sync/api/syncable_service.h" 14 15class ExtensionService; 16class ProfileSyncService; 17 18namespace sync_driver { 19class SyncPrefs; 20} 21 22namespace extensions { 23 24class SyncBundle; 25 26// A pending enable is when an app or extension is enabled locally before sync 27// has started. We track these to prevent sync data arriving and clobbering 28// local state, and also to ensure that these early enables get synced to the 29// server when sync does start. 30class PendingEnables { 31 public: 32 PendingEnables(scoped_ptr<sync_driver::SyncPrefs> sync_prefs, 33 SyncBundle* sync_bundle, 34 syncer::ModelType enable_type); 35 ~PendingEnables(); 36 37 // Called when an extension is enabled / disabled locally. 38 // These will check the sync state and figure out whether the change 39 // needs to be remembered for syncing when syncing starts. 40 void OnExtensionEnabled(const std::string& extension_id); 41 void OnExtensionDisabled(const std::string& extension_id); 42 43 // Called when |sync_bundle_| is ready to accept sync changes. 44 // Uses |service| to look up extensions from extension ids. 45 void OnSyncStarted(ExtensionService* service); 46 47 // Whether |extension_id| has a pending enable. 48 bool Contains(const std::string& extension_id) const; 49 50 private: 51 bool IsSyncEnabled(); 52 bool IsWaitingForSync(); 53 54 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; 55 SyncBundle* sync_bundle_; 56 syncer::ModelType enable_type_; 57 std::set<std::string> ids_; 58 59 bool is_sync_enabled_for_test_; 60 61 DISALLOW_COPY_AND_ASSIGN(PendingEnables); 62}; 63 64} // namespace extensions 65 66#endif // CHROME_BROWSER_EXTENSIONS_PENDING_ENABLES_H_ 67