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

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

Issue 7564037: Apps/Extensions Sync refactoring -- delete most of the old glue, implement new sync API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Release build warning :-/ Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/extension_util.h"
6
7 #include <sstream>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/version.h"
12 #include "chrome/browser/extensions/extension_sync_data.h"
13 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_constants.h"
16
17 namespace browser_sync {
18
19 bool IsExtensionValid(const Extension& extension) {
20 // TODO(akalin): Figure out if we need to allow some other types.
21 if (extension.location() != Extension::INTERNAL) {
22 // We have a non-standard location.
23 return false;
24 }
25
26 // Disallow extensions with non-gallery auto-update URLs for now.
27 //
28 // TODO(akalin): Relax this restriction once we've put in UI to
29 // approve synced extensions.
30 if (!extension.update_url().is_empty() &&
31 (extension.update_url() != Extension::GalleryUpdateUrl(false)) &&
32 (extension.update_url() != Extension::GalleryUpdateUrl(true))) {
33 return false;
34 }
35
36 // Disallow extensions with native code plugins.
37 //
38 // TODO(akalin): Relax this restriction once we've put in UI to
39 // approve synced extensions.
40 if (!extension.plugins().empty()) {
41 return false;
42 }
43
44 return true;
45 }
46
47 std::string ExtensionSpecificsToString(
48 const sync_pb::ExtensionSpecifics& specifics) {
49 std::stringstream ss;
50 ss << "{ ";
51 ss << "id: " << specifics.id() << ", ";
52 ss << "version: " << specifics.version() << ", ";
53 ss << "update_url: " << specifics.update_url() << ", ";
54 ss << "enabled: " << specifics.enabled() << ", ";
55 ss << "incognito_enabled: " << specifics.incognito_enabled() << ", ";
56 ss << "name: " << specifics.name();
57 ss << " }";
58 return ss.str();
59 }
60
61 bool SpecificsToSyncData(
62 const sync_pb::ExtensionSpecifics& specifics,
63 ExtensionSyncData* sync_data) {
64 if (!Extension::IdIsValid(specifics.id())) {
65 return false;
66 }
67
68 scoped_ptr<Version> version(
69 Version::GetVersionFromString(specifics.version()));
70 if (!version.get()) {
71 return false;
72 }
73
74 // The update URL must be either empty or valid.
75 GURL update_url(specifics.update_url());
76 if (!update_url.is_empty() && !update_url.is_valid()) {
77 return false;
78 }
79
80 sync_data->id = specifics.id();
81 sync_data->update_url = update_url;
82 sync_data->version = *version;
83 sync_data->enabled = specifics.enabled();
84 sync_data->incognito_enabled = specifics.incognito_enabled();
85 sync_data->name = specifics.name();
86 return true;
87 }
88
89 void SyncDataToSpecifics(
90 const ExtensionSyncData& sync_data,
91 sync_pb::ExtensionSpecifics* specifics) {
92 DCHECK(Extension::IdIsValid(sync_data.id));
93 DCHECK(!sync_data.uninstalled);
94 specifics->set_id(sync_data.id);
95 specifics->set_update_url(sync_data.update_url.spec());
96 specifics->set_version(sync_data.version.GetString());
97 specifics->set_enabled(sync_data.enabled);
98 specifics->set_incognito_enabled(sync_data.incognito_enabled);
99 specifics->set_name(sync_data.name);
100 }
101
102 } // 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