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

Side by Side Diff: sync/engine/download_updates_command.cc

Issue 10455012: [Sync] Add support for performing a GetKey on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fred's comments Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/engine/download_updates_command.h" 5 #include "sync/engine/download_updates_command.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "sync/engine/syncer.h" 10 #include "sync/engine/syncer.h"
11 #include "sync/engine/syncer_proto_util.h" 11 #include "sync/engine/syncer_proto_util.h"
12 #include "sync/internal_api/public/base/model_type_payload_map.h" 12 #include "sync/internal_api/public/base/model_type_payload_map.h"
13 #include "sync/syncable/directory.h" 13 #include "sync/syncable/directory.h"
14 #include "sync/syncable/read_transaction.h"
14 15
15 using sync_pb::DebugInfo; 16 using sync_pb::DebugInfo;
16 17
17 namespace syncer { 18 namespace syncer {
18 using sessions::StatusController; 19 using sessions::StatusController;
19 using sessions::SyncSession; 20 using sessions::SyncSession;
20 using std::string; 21 using std::string;
21 22
22 DownloadUpdatesCommand::DownloadUpdatesCommand( 23 DownloadUpdatesCommand::DownloadUpdatesCommand(
23 bool create_mobile_bookmarks_folder) 24 bool create_mobile_bookmarks_folder)
24 : create_mobile_bookmarks_folder_(create_mobile_bookmarks_folder) {} 25 : create_mobile_bookmarks_folder_(create_mobile_bookmarks_folder) {}
25 26
26 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} 27 DownloadUpdatesCommand::~DownloadUpdatesCommand() {}
27 28
29 namespace {
30
31 SyncerError HandleGetEncryptionKeyResponse(
32 const sync_pb::ClientToServerResponse& update_response,
33 syncable::Directory* dir) {
34 bool success = false;
35 if (!update_response.get_updates().has_encryption_key()) {
36 LOG(ERROR) << "Failed to receive encryption key from server.";
37 return SERVER_RESPONSE_VALIDATION_FAILED;
38 }
39 syncable::ReadTransaction trans(FROM_HERE, dir);
40 Cryptographer* cryptographer = dir->GetCryptographer(&trans);
41 success = cryptographer->SetKeystoreKey(
42 update_response.get_updates().encryption_key());
43
44 DVLOG(1) << "GetUpdates returned encryption key of length "
45 << update_response.get_updates().encryption_key().length()
46 << ". Cryptographer keystore key "
47 << (success ? "" : "not ") << "updated.";
48 return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED);
49 }
50
51 } // namespace
52
28 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { 53 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
29 sync_pb::ClientToServerMessage client_to_server_message; 54 sync_pb::ClientToServerMessage client_to_server_message;
30 sync_pb::ClientToServerResponse update_response; 55 sync_pb::ClientToServerResponse update_response;
31 56
32 client_to_server_message.set_share(session->context()->account_name()); 57 client_to_server_message.set_share(session->context()->account_name());
33 client_to_server_message.set_message_contents( 58 client_to_server_message.set_message_contents(
34 sync_pb::ClientToServerMessage::GET_UPDATES); 59 sync_pb::ClientToServerMessage::GET_UPDATES);
35 sync_pb::GetUpdatesMessage* get_updates = 60 sync_pb::GetUpdatesMessage* get_updates =
36 client_to_server_message.mutable_get_updates(); 61 client_to_server_message.mutable_get_updates();
37 get_updates->set_create_mobile_bookmarks_folder( 62 get_updates->set_create_mobile_bookmarks_folder(
(...skipping 16 matching lines...) Expand all
54 dir->GetDownloadProgress(it.Get(), progress_marker); 79 dir->GetDownloadProgress(it.Get(), progress_marker);
55 80
56 // Set notification hint if present. 81 // Set notification hint if present.
57 ModelTypePayloadMap::const_iterator type_payload = 82 ModelTypePayloadMap::const_iterator type_payload =
58 type_payload_map.find(it.Get()); 83 type_payload_map.find(it.Get());
59 if (type_payload != type_payload_map.end()) { 84 if (type_payload != type_payload_map.end()) {
60 progress_marker->set_notification_hint(type_payload->second); 85 progress_marker->set_notification_hint(type_payload->second);
61 } 86 }
62 } 87 }
63 88
89 bool need_encryption_key = false;
90 if (session->context()->keystore_encryption_enabled()) {
91 syncable::Directory* dir = session->context()->directory();
92 syncable::ReadTransaction trans(FROM_HERE, dir);
93 Cryptographer* cryptographer =
94 session->context()->directory()->GetCryptographer(&trans);
95 need_encryption_key = !cryptographer->HasKeystoreKey();
96 get_updates->set_need_encryption_key(need_encryption_key);
97
98 }
99
64 // We want folders for our associated types, always. If we were to set 100 // We want folders for our associated types, always. If we were to set
65 // this to false, the server would send just the non-container items 101 // this to false, the server would send just the non-container items
66 // (e.g. Bookmark URLs but not their containing folders). 102 // (e.g. Bookmark URLs but not their containing folders).
67 get_updates->set_fetch_folders(true); 103 get_updates->set_fetch_folders(true);
68 104
69 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. 105 // Set GetUpdatesMessage.GetUpdatesCallerInfo information.
70 get_updates->mutable_caller_info()->set_source( 106 get_updates->mutable_caller_info()->set_source(
71 session->source().updates_source); 107 session->source().updates_source);
72 get_updates->mutable_caller_info()->set_notifications_enabled( 108 get_updates->mutable_caller_info()->set_notifications_enabled(
73 session->context()->notifications_enabled()); 109 session->context()->notifications_enabled());
(...skipping 21 matching lines...) Expand all
95 return result; 131 return result;
96 } 132 }
97 133
98 status->mutable_updates_response()->CopyFrom(update_response); 134 status->mutable_updates_response()->CopyFrom(update_response);
99 135
100 DVLOG(1) << "GetUpdates " 136 DVLOG(1) << "GetUpdates "
101 << " returned " << update_response.get_updates().entries_size() 137 << " returned " << update_response.get_updates().entries_size()
102 << " updates and indicated " 138 << " updates and indicated "
103 << update_response.get_updates().changes_remaining() 139 << update_response.get_updates().changes_remaining()
104 << " updates left on server."; 140 << " updates left on server.";
141
142 if (need_encryption_key) {
143 status->set_last_get_key_result(
144 HandleGetEncryptionKeyResponse(update_response, dir));
145 }
146
105 return result; 147 return result;
106 } 148 }
107 149
108 void DownloadUpdatesCommand::AppendClientDebugInfoIfNeeded( 150 void DownloadUpdatesCommand::AppendClientDebugInfoIfNeeded(
109 sessions::SyncSession* session, 151 sessions::SyncSession* session,
110 DebugInfo* debug_info) { 152 DebugInfo* debug_info) {
111 // We want to send the debug info only once per sync cycle. Check if it has 153 // We want to send the debug info only once per sync cycle. Check if it has
112 // already been sent. 154 // already been sent.
113 if (!session->status_controller().debug_info_sent()) { 155 if (!session->status_controller().debug_info_sent()) {
114 DVLOG(1) << "Sending client debug info ..."; 156 DVLOG(1) << "Sending client debug info ...";
115 // could be null in some unit tests. 157 // could be null in some unit tests.
116 if (session->context()->debug_info_getter()) { 158 if (session->context()->debug_info_getter()) {
117 session->context()->debug_info_getter()->GetAndClearDebugInfo( 159 session->context()->debug_info_getter()->GetAndClearDebugInfo(
118 debug_info); 160 debug_info);
119 } 161 }
120 session->mutable_status_controller()->set_debug_info_sent(); 162 session->mutable_status_controller()->set_debug_info_sent();
121 } 163 }
122 } 164 }
123 165
124 } // namespace syncer 166 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698