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

Side by Side Diff: chrome/browser/extensions/extension_sync_data.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
1 // Copyright (c) 2011 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/extensions/extension_sync_data.h" 5 #include "chrome/browser/extensions/extension_sync_data.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/sync/protocol/app_specifics.pb.h"
10 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
8 11
9 ExtensionSyncData::ExtensionSyncData() 12 ExtensionSyncData::ExtensionSyncData()
10 : uninstalled(false), enabled(false), incognito_enabled(false) {} 13 : uninstalled_(false),
14 enabled_(false),
15 incognito_enabled_(false),
16 type_(Extension::SYNC_TYPE_NONE) {
17 }
18
19 ExtensionSyncData::ExtensionSyncData(const SyncData& sync_data)
20 : uninstalled_(false),
21 enabled_(false),
22 incognito_enabled_(false),
23 type_(Extension::SYNC_TYPE_NONE) {
24 PopulateFromSyncData(sync_data);
25 }
26
27 ExtensionSyncData::ExtensionSyncData(const SyncChange& sync_change)
28 : uninstalled_(sync_change.change_type() == SyncChange::ACTION_DELETE) {
29 PopulateFromSyncData(sync_change.sync_data());
30 }
31
32 ExtensionSyncData::ExtensionSyncData(const Extension& extension,
33 bool enabled,
34 bool incognito_enabled)
35 : id_(extension.id()),
36 uninstalled_(false),
37 enabled_(enabled),
38 incognito_enabled_(incognito_enabled),
39 type_(extension.GetSyncType()),
40 version_(*extension.version()),
41 update_url_(extension.update_url()),
42 name_(extension.name()) {
43 }
11 44
12 ExtensionSyncData::~ExtensionSyncData() {} 45 ExtensionSyncData::~ExtensionSyncData() {}
13 46
14 void ExtensionSyncData::Merge(const ExtensionSyncData& new_data) { 47 void ExtensionSyncData::PopulateSyncSpecifics(
15 CHECK_EQ(id, new_data.id); 48 sync_pb::ExtensionSpecifics* specifics) const {
16 CHECK(!uninstalled); 49 DCHECK(Extension::IdIsValid(id_));
17 CHECK(!new_data.uninstalled); 50 specifics->set_id(id_);
51 specifics->set_update_url(update_url_.spec());
52 specifics->set_version(version_.GetString());
53 specifics->set_enabled(enabled_);
54 specifics->set_incognito_enabled(incognito_enabled_);
55 specifics->set_name(name_);
56 }
18 57
19 // Copy version-independent properties. 58 SyncData ExtensionSyncData::GetSyncData() const {
20 enabled = new_data.enabled; 59 sync_pb::EntitySpecifics specifics;
21 incognito_enabled = new_data.incognito_enabled; 60 sync_pb::ExtensionSpecifics* extension_specifics = NULL;
22 61
23 // Copy version-dependent properties if version <= new_data.version. 62 switch (type_) {
24 if (version.CompareTo(new_data.version) <= 0) { 63 case Extension::SYNC_TYPE_EXTENSION:
25 version = new_data.version; 64 extension_specifics = specifics.MutableExtension(sync_pb::extension);
26 update_url = new_data.update_url; 65 break;
27 name = new_data.name; 66 case Extension::SYNC_TYPE_APP:
67 extension_specifics =
68 specifics.MutableExtension(sync_pb::app)->mutable_extension();
69 break;
70 default:
71 LOG(FATAL) << "Attempt to get non-syncable data.";
28 } 72 }
73
74 PopulateSyncSpecifics(extension_specifics);
75
76 return SyncData::CreateLocalData(id_, name_, specifics);
29 } 77 }
78
79 SyncChange ExtensionSyncData::GetSyncChange(
80 SyncChange::SyncChangeType change_type) const {
81 return SyncChange(change_type, GetSyncData());
82 }
83
84 void ExtensionSyncData::PopulateFromExtensionSpecifics(
85 const sync_pb::ExtensionSpecifics& specifics) {
86 if (!Extension::IdIsValid(specifics.id())) {
87 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
88 }
89
90 scoped_ptr<Version> specifics_version(
91 Version::GetVersionFromString(specifics.version()));
92 if (!specifics_version.get()) {
93 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
94 }
95
96 // The update URL must be either empty or valid.
97 GURL specifics_update_url(specifics.update_url());
98 if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) {
99 LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
100 }
101
102 id_ = specifics.id();
103 update_url_ = specifics_update_url;
104 version_ = *specifics_version;
105 enabled_ = specifics.enabled();
106 incognito_enabled_ = specifics.incognito_enabled();
107 name_ = specifics.name();
108 }
109
110 void ExtensionSyncData::PopulateFromSyncData(const SyncData& sync_data) {
111 const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics();
112 sync_pb::ExtensionSpecifics extension_expecifics;
113 if (entity_specifics.HasExtension(sync_pb::extension)) {
114 extension_expecifics = entity_specifics.GetExtension(sync_pb::extension);
115 type_ = Extension::SYNC_TYPE_EXTENSION;
116 } else if (entity_specifics.HasExtension(sync_pb::app)) {
117 extension_expecifics =
118 entity_specifics.GetExtension(sync_pb::app).extension();
119 type_ = Extension::SYNC_TYPE_APP;
120 } else {
121 LOG(FATAL) << "Attempt to sync bad EntitySpecifics.";
122 }
123 PopulateFromExtensionSpecifics(extension_expecifics);
124 }
125
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_sync_data.h ('k') | chrome/browser/extensions/extension_sync_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698