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

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

Issue 10878015: [Sync] Move keystore key handling to SyncEncryptionHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 3 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
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.cc ('k') | sync/engine/syncer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_state_map.h" 12 #include "sync/internal_api/public/base/model_type_state_map.h"
13 #include "sync/syncable/directory.h" 13 #include "sync/syncable/directory.h"
14 #include "sync/syncable/nigori_handler.h"
14 #include "sync/syncable/read_transaction.h" 15 #include "sync/syncable/read_transaction.h"
15 #include "sync/util/cryptographer.h"
16 16
17 using sync_pb::DebugInfo; 17 using sync_pb::DebugInfo;
18 18
19 namespace syncer { 19 namespace syncer {
20 using sessions::StatusController; 20 using sessions::StatusController;
21 using sessions::SyncSession; 21 using sessions::SyncSession;
22 using std::string; 22 using std::string;
23 23
24 DownloadUpdatesCommand::DownloadUpdatesCommand( 24 DownloadUpdatesCommand::DownloadUpdatesCommand(
25 bool create_mobile_bookmarks_folder) 25 bool create_mobile_bookmarks_folder)
26 : create_mobile_bookmarks_folder_(create_mobile_bookmarks_folder) {} 26 : create_mobile_bookmarks_folder_(create_mobile_bookmarks_folder) {}
27 27
28 DownloadUpdatesCommand::~DownloadUpdatesCommand() {} 28 DownloadUpdatesCommand::~DownloadUpdatesCommand() {}
29 29
30 namespace { 30 namespace {
31 31
32 SyncerError HandleGetEncryptionKeyResponse( 32 SyncerError HandleGetEncryptionKeyResponse(
33 const sync_pb::ClientToServerResponse& update_response, 33 const sync_pb::ClientToServerResponse& update_response,
34 syncable::Directory* dir) { 34 syncable::Directory* dir) {
35 bool success = false; 35 bool success = false;
36 if (!update_response.get_updates().has_encryption_key()) { 36 if (!update_response.get_updates().has_encryption_key()) {
37 LOG(ERROR) << "Failed to receive encryption key from server."; 37 LOG(ERROR) << "Failed to receive encryption key from server.";
38 return SERVER_RESPONSE_VALIDATION_FAILED; 38 return SERVER_RESPONSE_VALIDATION_FAILED;
39 } 39 }
40 syncable::ReadTransaction trans(FROM_HERE, dir); 40 syncable::ReadTransaction trans(FROM_HERE, dir);
41 Cryptographer* cryptographer = dir->GetCryptographer(&trans); 41 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler();
42 success = cryptographer->SetKeystoreKey( 42 success = nigori_handler->SetKeystoreKey(
43 update_response.get_updates().encryption_key()); 43 update_response.get_updates().encryption_key(),
44 &trans);
44 45
45 DVLOG(1) << "GetUpdates returned encryption key of length " 46 DVLOG(1) << "GetUpdates returned encryption key of length "
46 << update_response.get_updates().encryption_key().length() 47 << update_response.get_updates().encryption_key().length()
47 << ". Cryptographer keystore key " 48 << ". Nigori keystore key "
48 << (success ? "" : "not ") << "updated."; 49 << (success ? "" : "not ") << "updated.";
49 return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED); 50 return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED);
50 } 51 }
51 52
52 } // namespace 53 } // namespace
53 54
54 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { 55 SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) {
55 sync_pb::ClientToServerMessage client_to_server_message; 56 sync_pb::ClientToServerMessage client_to_server_message;
56 sync_pb::ClientToServerResponse update_response; 57 sync_pb::ClientToServerResponse update_response;
57 58
(...skipping 26 matching lines...) Expand all
84 type_state_map.find(it.Get()); 85 type_state_map.find(it.Get());
85 if (type_state != type_state_map.end()) { 86 if (type_state != type_state_map.end()) {
86 progress_marker->set_notification_hint(type_state->second.payload); 87 progress_marker->set_notification_hint(type_state->second.payload);
87 } 88 }
88 } 89 }
89 90
90 bool need_encryption_key = false; 91 bool need_encryption_key = false;
91 if (session->context()->keystore_encryption_enabled()) { 92 if (session->context()->keystore_encryption_enabled()) {
92 syncable::Directory* dir = session->context()->directory(); 93 syncable::Directory* dir = session->context()->directory();
93 syncable::ReadTransaction trans(FROM_HERE, dir); 94 syncable::ReadTransaction trans(FROM_HERE, dir);
94 Cryptographer* cryptographer = 95 syncable::NigoriHandler* nigori_handler = dir->GetNigoriHandler();
95 session->context()->directory()->GetCryptographer(&trans); 96 need_encryption_key = nigori_handler->NeedKeystoreKey(&trans);
96 need_encryption_key = !cryptographer->HasKeystoreKey();
97 get_updates->set_need_encryption_key(need_encryption_key); 97 get_updates->set_need_encryption_key(need_encryption_key);
98 98
99 } 99 }
100 100
101 // We want folders for our associated types, always. If we were to set 101 // We want folders for our associated types, always. If we were to set
102 // this to false, the server would send just the non-container items 102 // this to false, the server would send just the non-container items
103 // (e.g. Bookmark URLs but not their containing folders). 103 // (e.g. Bookmark URLs but not their containing folders).
104 get_updates->set_fetch_folders(true); 104 get_updates->set_fetch_folders(true);
105 105
106 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. 106 // Set GetUpdatesMessage.GetUpdatesCallerInfo information.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // could be null in some unit tests. 158 // could be null in some unit tests.
159 if (session->context()->debug_info_getter()) { 159 if (session->context()->debug_info_getter()) {
160 session->context()->debug_info_getter()->GetAndClearDebugInfo( 160 session->context()->debug_info_getter()->GetAndClearDebugInfo(
161 debug_info); 161 debug_info);
162 } 162 }
163 session->mutable_status_controller()->set_debug_info_sent(); 163 session->mutable_status_controller()->set_debug_info_sent();
164 } 164 }
165 } 165 }
166 166
167 } // namespace syncer 167 } // namespace syncer
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.cc ('k') | sync/engine/syncer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698