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

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

Issue 6852029: [Sync] Move some extension-sync-related logic to ExtensionService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO, fix lint Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_sync_traits.h" 5 #include "chrome/browser/sync/glue/extension_sync_traits.h"
6 6
7 #include "base/string_piece.h" 7 #include "base/string_piece.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/sync/engine/syncapi.h" 9 #include "chrome/browser/sync/engine/syncapi.h"
10 #include "chrome/browser/sync/glue/extension_util.h" 10 #include "chrome/browser/sync/glue/extension_util.h"
11 #include "chrome/browser/sync/protocol/app_specifics.pb.h" 11 #include "chrome/browser/sync/protocol/app_specifics.pb.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 bool GetExtensionSpecificsFromEntity( 50 bool GetExtensionSpecificsFromEntity(
51 const sync_pb::EntitySpecifics& entity_specifics, 51 const sync_pb::EntitySpecifics& entity_specifics,
52 sync_pb::ExtensionSpecifics* extension_specifics) { 52 sync_pb::ExtensionSpecifics* extension_specifics) {
53 if (!entity_specifics.HasExtension(sync_pb::extension)) { 53 if (!entity_specifics.HasExtension(sync_pb::extension)) {
54 return false; 54 return false;
55 } 55 }
56 *extension_specifics = entity_specifics.GetExtension(sync_pb::extension); 56 *extension_specifics = entity_specifics.GetExtension(sync_pb::extension);
57 return true; 57 return true;
58 } 58 }
59 59
60 bool IsSyncableExtension(Extension::Type type, const GURL& update_url) {
61 switch (type) {
62 case Extension::TYPE_EXTENSION:
63 return true;
64 case Extension::TYPE_USER_SCRIPT:
65 // We only want to sync user scripts with update URLs.
66 return !update_url.is_empty();
67 default:
68 return false;
69 }
70 }
71
72 bool IsValidAndSyncableExtension(const Extension& extension) {
73 return
74 IsExtensionValid(extension) &&
75 IsSyncableExtension(extension.GetType(), extension.update_url());
76 }
77
78 bool IsExtensionUninstall( 60 bool IsExtensionUninstall(
79 const UninstalledExtensionInfo& uninstalled_extension_info) { 61 const UninstalledExtensionInfo& uninstalled_extension_info) {
80 return IsSyncableExtension(uninstalled_extension_info.extension_type, 62 return IsSyncableExtension(uninstalled_extension_info.extension_type,
81 uninstalled_extension_info.update_url); 63 uninstalled_extension_info.update_url);
82 } 64 }
83 65
84 } // namespace 66 } // namespace
85 67
86 ExtensionSyncTraits GetExtensionSyncTraits() { 68 ExtensionSyncTraits GetExtensionSyncTraits() {
87 return ExtensionSyncTraits(syncable::EXTENSIONS, 69 return ExtensionSyncTraits(syncable::EXTENSIONS,
(...skipping 25 matching lines...) Expand all
113 const sync_pb::EntitySpecifics& entity_specifics, 95 const sync_pb::EntitySpecifics& entity_specifics,
114 sync_pb::ExtensionSpecifics* extension_specifics) { 96 sync_pb::ExtensionSpecifics* extension_specifics) {
115 if (!entity_specifics.HasExtension(sync_pb::app)) { 97 if (!entity_specifics.HasExtension(sync_pb::app)) {
116 return false; 98 return false;
117 } 99 }
118 *extension_specifics = 100 *extension_specifics =
119 entity_specifics.GetExtension(sync_pb::app).extension(); 101 entity_specifics.GetExtension(sync_pb::app).extension();
120 return true; 102 return true;
121 } 103 }
122 104
123 bool IsSyncableApp(Extension::Type type) {
124 return
125 (type == Extension::TYPE_HOSTED_APP) ||
126 (type == Extension::TYPE_PACKAGED_APP);
127 }
128
129 bool IsValidAndSyncableApp(
130 const Extension& extension) {
131 return IsExtensionValid(extension) && IsSyncableApp(extension.GetType());
132 }
133
134 bool IsAppUninstall( 105 bool IsAppUninstall(
135 const UninstalledExtensionInfo& uninstalled_extension_info) { 106 const UninstalledExtensionInfo& uninstalled_extension_info) {
136 return IsSyncableApp(uninstalled_extension_info.extension_type); 107 return IsSyncableApp(uninstalled_extension_info.extension_type);
137 } 108 }
138 109
139 } // namespace 110 } // namespace
140 111
141 ExtensionSyncTraits GetAppSyncTraits() { 112 ExtensionSyncTraits GetAppSyncTraits() {
142 return ExtensionSyncTraits(syncable::APPS, 113 return ExtensionSyncTraits(syncable::APPS,
143 &IsValidAndSyncableApp, 114 &IsValidAndSyncableApp,
144 &IsAppUninstall, 115 &IsAppUninstall,
145 "google_chrome_apps", 116 "google_chrome_apps",
146 &GetExtensionSpecificsOfApp, 117 &GetExtensionSpecificsOfApp,
147 &SetExtensionSpecificsOfApp, 118 &SetExtensionSpecificsOfApp,
148 &GetExtensionSpecificsFromEntityOfApp); 119 &GetExtensionSpecificsFromEntityOfApp);
149 } 120 }
150 121
151 } // namespace browser_sync 122 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698