Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/sync/glue/extension_util.cc

Issue 3110008: Massive refactoring of extensions sync code (Closed) Base URL: 76.121.192.83:~/projects/chromium/src
Patch Set: Fixed compile error Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/sync/glue/extension_util.h" 5 #include "chrome/browser/sync/glue/extension_util.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/stl_util-inl.h"
11 #include "base/version.h" 12 #include "base/version.h"
12 #include "chrome/browser/extensions/extensions_service.h" 13 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 14 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
14 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 18
18 namespace browser_sync { 19 namespace browser_sync {
19 20
20 bool IsExtensionSyncable(const Extension& extension) { 21 ExtensionType GetExtensionType(const Extension& extension) {
21 if (extension.is_theme()) { 22 if (extension.is_theme()) {
22 return false; 23 return THEME;
23 } 24 }
24 25
25 // TODO(akalin): Add Extensions::is_app(). 26 // TODO(akalin): Add Extensions::is_app().
26 if (!extension.GetFullLaunchURL().is_empty()) { 27 if (!extension.GetFullLaunchURL().is_empty()) {
27 // We have an app. 28 return APP;
28 return false;
29 } 29 }
30 30
31 if (extension.converted_from_user_script()) {
32 return USER_SCRIPT;
33 }
34
35 // Otherwise, we just have a regular extension.
36 return EXTENSION;
37 }
38
39 bool IsExtensionValid(const Extension& extension) {
31 // TODO(akalin): Figure out if we need to allow some other types. 40 // TODO(akalin): Figure out if we need to allow some other types.
32 if (extension.location() != Extension::INTERNAL) { 41 if (extension.location() != Extension::INTERNAL) {
33 // We have a non-standard location. 42 // We have a non-standard location.
34 return false; 43 return false;
35 } 44 }
36 45
37 // Disallow extensions with non-gallery auto-update URLs for now. 46 // Disallow extensions with non-gallery auto-update URLs for now.
38 // 47 //
39 // TODO(akalin): Relax this restriction once we've put in UI to 48 // TODO(akalin): Relax this restriction once we've put in UI to
40 // approve synced extensions. 49 // approve synced extensions.
41 if (!extension.update_url().is_empty() && 50 if (!extension.update_url().is_empty() &&
42 (extension.update_url() != 51 (extension.update_url() !=
43 GURL(extension_urls::kGalleryUpdateHttpUrl)) && 52 GURL(extension_urls::kGalleryUpdateHttpUrl)) &&
44 (extension.update_url() != 53 (extension.update_url() !=
45 GURL(extension_urls::kGalleryUpdateHttpsUrl))) { 54 GURL(extension_urls::kGalleryUpdateHttpsUrl))) {
46 return false; 55 return false;
47 } 56 }
48 57
49 // Disallow extensions with native code plugins. 58 // Disallow extensions with native code plugins.
50 // 59 //
51 // TODO(akalin): Relax this restriction once we've put in UI to 60 // TODO(akalin): Relax this restriction once we've put in UI to
52 // approve synced extensions. 61 // approve synced extensions.
53 if (!extension.plugins().empty()) { 62 if (!extension.plugins().empty()) {
54 return false; 63 return false;
55 } 64 }
56 65
57 return true; 66 return true;
58 } 67 }
59 68
69 bool IsExtensionValidAndSyncable(const Extension& extension,
70 const ExtensionTypeSet& allowed_types) {
71 return
72 IsExtensionValid(extension) &&
73 ContainsKey(allowed_types, GetExtensionType(extension));
74 }
75
60 std::string ExtensionSpecificsToString( 76 std::string ExtensionSpecificsToString(
61 const sync_pb::ExtensionSpecifics& specifics) { 77 const sync_pb::ExtensionSpecifics& specifics) {
62 std::stringstream ss; 78 std::stringstream ss;
63 ss << "{ "; 79 ss << "{ ";
64 ss << "id: " << specifics.id() << ", "; 80 ss << "id: " << specifics.id() << ", ";
65 ss << "version: " << specifics.version() << ", "; 81 ss << "version: " << specifics.version() << ", ";
66 ss << "update_url: " << specifics.update_url() << ", "; 82 ss << "update_url: " << specifics.update_url() << ", ";
67 ss << "enabled: " << specifics.enabled() << ", "; 83 ss << "enabled: " << specifics.enabled() << ", ";
68 ss << "incognito_enabled: " << specifics.incognito_enabled() << ", "; 84 ss << "incognito_enabled: " << specifics.incognito_enabled() << ", ";
69 ss << "name: " << specifics.name(); 85 ss << "name: " << specifics.name();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 extensions_service->GetExtensionById(id, false) != NULL; 176 extensions_service->GetExtensionById(id, false) != NULL;
161 bool incognito_enabled = 177 bool incognito_enabled =
162 extensions_service->IsIncognitoEnabled(&extension); 178 extensions_service->IsIncognitoEnabled(&extension);
163 GetExtensionSpecificsHelper(extension, enabled, incognito_enabled, 179 GetExtensionSpecificsHelper(extension, enabled, incognito_enabled,
164 specifics); 180 specifics);
165 } 181 }
166 182
167 void GetExtensionSpecificsHelper(const Extension& extension, 183 void GetExtensionSpecificsHelper(const Extension& extension,
168 bool enabled, bool incognito_enabled, 184 bool enabled, bool incognito_enabled,
169 sync_pb::ExtensionSpecifics* specifics) { 185 sync_pb::ExtensionSpecifics* specifics) {
170 DCHECK(IsExtensionSyncable(extension)); 186 DCHECK(IsExtensionValid(extension));
171 const std::string& id = extension.id(); 187 const std::string& id = extension.id();
172 specifics->set_id(id); 188 specifics->set_id(id);
173 specifics->set_version(extension.VersionString()); 189 specifics->set_version(extension.VersionString());
174 specifics->set_update_url(extension.update_url().spec()); 190 specifics->set_update_url(extension.update_url().spec());
175 specifics->set_enabled(enabled); 191 specifics->set_enabled(enabled);
176 specifics->set_incognito_enabled(incognito_enabled); 192 specifics->set_incognito_enabled(incognito_enabled);
177 specifics->set_name(extension.name()); 193 specifics->set_name(extension.name());
178 DcheckIsExtensionSpecificsValid(*specifics); 194 DcheckIsExtensionSpecificsValid(*specifics);
179 } 195 }
180 196
181 bool IsExtensionOutdated(const Extension& extension, 197 bool IsExtensionOutdated(const Extension& extension,
182 const sync_pb::ExtensionSpecifics& specifics) { 198 const sync_pb::ExtensionSpecifics& specifics) {
183 DCHECK(IsExtensionSyncable(extension)); 199 DCHECK(IsExtensionValid(extension));
184 DcheckIsExtensionSpecificsValid(specifics); 200 DcheckIsExtensionSpecificsValid(specifics);
185 scoped_ptr<Version> specifics_version( 201 scoped_ptr<Version> specifics_version(
186 Version::GetVersionFromString(specifics.version())); 202 Version::GetVersionFromString(specifics.version()));
187 if (!specifics_version.get()) { 203 if (!specifics_version.get()) {
188 // If version is invalid, assume we're up-to-date. 204 // If version is invalid, assume we're up-to-date.
189 return false; 205 return false;
190 } 206 }
191 return extension.version()->CompareTo(*specifics_version) < 0; 207 return extension.version()->CompareTo(*specifics_version) < 0;
192 } 208 }
193 209
194 void SetExtensionProperties( 210 void SetExtensionProperties(
195 const sync_pb::ExtensionSpecifics& specifics, 211 const sync_pb::ExtensionSpecifics& specifics,
196 ExtensionsService* extensions_service, Extension* extension) { 212 ExtensionsService* extensions_service, Extension* extension) {
197 DcheckIsExtensionSpecificsValid(specifics); 213 DcheckIsExtensionSpecificsValid(specifics);
198 CHECK(extensions_service); 214 CHECK(extensions_service);
199 CHECK(extension); 215 CHECK(extension);
200 DCHECK(IsExtensionSyncable(*extension)); 216 DCHECK(IsExtensionValid(*extension));
201 const std::string& id = extension->id(); 217 const std::string& id = extension->id();
202 GURL update_url(specifics.update_url()); 218 GURL update_url(specifics.update_url());
203 if (update_url != extension->update_url()) { 219 if (update_url != extension->update_url()) {
204 LOG(WARNING) << "specifics for extension " << id 220 LOG(WARNING) << "specifics for extension " << id
205 << "has a different update URL than the extension: " 221 << "has a different update URL than the extension: "
206 << update_url.spec() << " vs. " << extension->update_url(); 222 << update_url.spec() << " vs. " << extension->update_url();
207 } 223 }
208 bool enabled = extensions_service->GetExtensionById(id, false) != NULL; 224 bool enabled = extensions_service->GetExtensionById(id, false) != NULL;
209 if (enabled && !specifics.enabled()) { 225 if (enabled && !specifics.enabled()) {
210 extensions_service->DisableExtension(id); 226 extensions_service->DisableExtension(id);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // |specifics| has a more recent or the same version, so merge it 258 // |specifics| has a more recent or the same version, so merge it
243 // in. 259 // in.
244 CopyNonUserProperties(specifics, merged_specifics); 260 CopyNonUserProperties(specifics, merged_specifics);
245 if (merge_user_properties) { 261 if (merge_user_properties) {
246 CopyUserProperties(specifics, merged_specifics); 262 CopyUserProperties(specifics, merged_specifics);
247 } 263 }
248 } 264 }
249 } 265 }
250 266
251 } // namespace browser_sync 267 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/extension_util.h ('k') | chrome/browser/sync/glue/extension_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698