OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_GLUE_EXTENSION_MODEL_ASSOCIATOR_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_EXTENSION_MODEL_ASSOCIATOR_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_EXTENSION_MODEL_ASSOCIATOR_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_EXTENSION_MODEL_ASSOCIATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
12 #include "chrome/browser/sync/glue/extension_data.h" | |
13 #include "chrome/browser/sync/glue/model_associator.h" | 10 #include "chrome/browser/sync/glue/model_associator.h" |
14 #include "chrome/browser/sync/syncable/model_type.h" | 11 #include "chrome/browser/sync/syncable/model_type.h" |
15 #include "chrome/common/extensions/extension.h" | |
16 | 12 |
17 class ExtensionsService; | |
18 class Profile; | |
19 class ProfileSyncService; | 13 class ProfileSyncService; |
20 | 14 |
21 namespace sync_api { | |
22 class ReadNode; | |
23 class WriteTransaction; | |
24 } // namespace sync_api | |
25 | |
26 namespace sync_pb { | |
27 class ExtensionSpecifics; | |
28 } // namespace sync_pb | |
29 | |
30 namespace browser_sync { | 15 namespace browser_sync { |
31 | 16 |
32 // Contains all logic for associating the Chrome extensions model and | 17 // Contains all logic for associating the Chrome extensions model and |
33 // the sync extensions model. | 18 // the sync extensions model. |
34 class ExtensionModelAssociator : public AssociatorInterface { | 19 class ExtensionModelAssociator : public AssociatorInterface { |
35 public: | 20 public: |
36 // Does not take ownership of sync_service. | 21 // Does not take ownership of sync_service. |
37 explicit ExtensionModelAssociator(ProfileSyncService* sync_service); | 22 explicit ExtensionModelAssociator(ProfileSyncService* sync_service); |
38 virtual ~ExtensionModelAssociator(); | 23 virtual ~ExtensionModelAssociator(); |
39 | 24 |
40 // Used by profile_sync_test_util.h. | 25 // Used by profile_sync_test_util.h. |
41 static syncable::ModelType model_type() { return syncable::EXTENSIONS; } | 26 static syncable::ModelType model_type() { return syncable::EXTENSIONS; } |
42 | 27 |
43 // AssociatorInterface implementation. | 28 // AssociatorInterface implementation. |
44 virtual bool AssociateModels(); | 29 virtual bool AssociateModels(); |
45 virtual bool DisassociateModels(); | 30 virtual bool DisassociateModels(); |
46 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); | 31 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); |
47 virtual void AbortAssociation() { | 32 virtual void AbortAssociation() { |
48 // No implementation needed, this associator runs on the main | 33 // No implementation needed, this associator runs on the main |
49 // thread. | 34 // thread. |
50 } | 35 } |
51 | 36 |
52 // Used by ExtensionChangeProcessor. | |
53 // | |
54 // TODO(akalin): These functions can actually be moved to the | |
55 // ChangeProcessor after some refactoring. | |
56 | |
57 // TODO(akalin): Return an error string instead of just a bool. | |
58 bool OnClientUpdate(const std::string& id); | |
59 void OnServerUpdate(const sync_pb::ExtensionSpecifics& server_data); | |
60 void OnServerRemove(const std::string& id); | |
61 | |
62 private: | 37 private: |
63 // Returns the extension service from |sync_service_|. Never | 38 // Weak pointer. Always non-NULL. |
64 // returns NULL. | |
65 ExtensionsService* GetExtensionsService(); | |
66 | |
67 bool GetExtensionDataFromServer( | |
68 const std::string& id, sync_api::WriteTransaction* trans, | |
69 const sync_api::ReadNode& root, | |
70 sync_pb::ExtensionSpecifics* server_data); | |
71 | |
72 // Updates the server data from the given extension data. | |
73 // extension_data->ServerNeedsUpdate() must hold before this | |
74 // function is called. Returns whether or not the update was | |
75 // successful. If the update was successful, | |
76 // extension_data->ServerNeedsUpdate() will be false after this | |
77 // function is called. This function leaves | |
78 // extension_data->ClientNeedsUpdate() unchanged. | |
79 bool UpdateServer(ExtensionData* extension_data, | |
80 sync_api::WriteTransaction* trans, | |
81 const sync_api::ReadNode& root); | |
82 | |
83 // Tries to update the client data from the given extension data. | |
84 // extension_data->ServerNeedsUpdate() must not hold and | |
85 // extension_data->ClientNeedsUpdate() must hold before this | |
86 // function is called. If the update was successful, | |
87 // extension_data->ClientNeedsUpdate() will be false after this | |
88 // function is called. Otherwise, the extension needs updating to a | |
89 // new version. | |
90 void TryUpdateClient(ExtensionData* extension_data); | |
91 | |
92 // Kick off a run of the extension updater. | |
93 // | |
94 // TODO(akalin): Combine this with the similar function in | |
95 // theme_util.cc. | |
96 void NudgeExtensionUpdater(); | |
97 | |
98 // Weak pointer. | |
99 ProfileSyncService* sync_service_; | 39 ProfileSyncService* sync_service_; |
100 | 40 |
101 DISALLOW_COPY_AND_ASSIGN(ExtensionModelAssociator); | 41 DISALLOW_COPY_AND_ASSIGN(ExtensionModelAssociator); |
102 }; | 42 }; |
103 | 43 |
104 } // namespace browser_sync | 44 } // namespace browser_sync |
105 | 45 |
106 #endif // CHROME_BROWSER_SYNC_GLUE_EXTENSION_MODEL_ASSOCIATOR_H_ | 46 #endif // CHROME_BROWSER_SYNC_GLUE_EXTENSION_MODEL_ASSOCIATOR_H_ |
OLD | NEW |