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

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: Move GetEncryptionKey logic into GetUpdates Created 8 years, 5 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)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 dir->GetDownloadProgress(it.Get(), progress_marker); 56 dir->GetDownloadProgress(it.Get(), progress_marker);
56 57
57 // Set notification hint if present. 58 // Set notification hint if present.
58 syncer::ModelTypePayloadMap::const_iterator type_payload = 59 syncer::ModelTypePayloadMap::const_iterator type_payload =
59 type_payload_map.find(it.Get()); 60 type_payload_map.find(it.Get());
60 if (type_payload != type_payload_map.end()) { 61 if (type_payload != type_payload_map.end()) {
61 progress_marker->set_notification_hint(type_payload->second); 62 progress_marker->set_notification_hint(type_payload->second);
62 } 63 }
63 } 64 }
64 65
66 bool need_encryption_key = false;
67 if (session->context()->keystore_encryption_enabled()) {
68 syncable::Directory* dir = session->context()->directory();
69 syncable::ReadTransaction trans(FROM_HERE, dir);
70 Cryptographer* cryptographer =
71 session->context()->directory()->GetCryptographer(&trans);
72 need_encryption_key = !cryptographer->HasKeystoreKey();
73 get_updates->set_need_encryption_key(need_encryption_key);
74
75 }
76
65 // We want folders for our associated types, always. If we were to set 77 // We want folders for our associated types, always. If we were to set
66 // this to false, the server would send just the non-container items 78 // this to false, the server would send just the non-container items
67 // (e.g. Bookmark URLs but not their containing folders). 79 // (e.g. Bookmark URLs but not their containing folders).
68 get_updates->set_fetch_folders(true); 80 get_updates->set_fetch_folders(true);
69 81
70 // Set GetUpdatesMessage.GetUpdatesCallerInfo information. 82 // Set GetUpdatesMessage.GetUpdatesCallerInfo information.
71 get_updates->mutable_caller_info()->set_source( 83 get_updates->mutable_caller_info()->set_source(
72 session->source().updates_source); 84 session->source().updates_source);
73 get_updates->mutable_caller_info()->set_notifications_enabled( 85 get_updates->mutable_caller_info()->set_notifications_enabled(
74 session->context()->notifications_enabled()); 86 session->context()->notifications_enabled());
(...skipping 21 matching lines...) Expand all
96 return result; 108 return result;
97 } 109 }
98 110
99 status->mutable_updates_response()->CopyFrom(update_response); 111 status->mutable_updates_response()->CopyFrom(update_response);
100 112
101 DVLOG(1) << "GetUpdates " 113 DVLOG(1) << "GetUpdates "
102 << " returned " << update_response.get_updates().entries_size() 114 << " returned " << update_response.get_updates().entries_size()
103 << " updates and indicated " 115 << " updates and indicated "
104 << update_response.get_updates().changes_remaining() 116 << update_response.get_updates().changes_remaining()
105 << " updates left on server."; 117 << " updates left on server.";
118
119 if (need_encryption_key) {
tim (not reviewing) 2012/07/26 21:53:15 Can you put this into a helper method for sake of
Nicolas Zea 2012/07/27 00:43:15 Done.
120 bool success = false;
121 if (update_response.get_updates().has_encryption_key()) {
122 syncable::Directory* dir = session->context()->directory();
123 syncable::ReadTransaction trans(FROM_HERE, dir);
124 Cryptographer* cryptographer =
125 session->context()->directory()->GetCryptographer(&trans);
126 success = cryptographer->SetKeystoreKey(
127 update_response.get_updates().encryption_key());
128
129 DVLOG(1) << "GetUpdates returned encryption key of length "
130 << update_response.get_updates().encryption_key().length()
131 << ". Cryptographer keystore key "
132 << (success ? "" : "not ") << "updated.";
133 } else {
134 LOG(ERROR) << "Failed to receive encryption key from server.";
135 }
136 status->set_last_get_key_result(
137 success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED);
138 }
139
106 return result; 140 return result;
107 } 141 }
108 142
109 void DownloadUpdatesCommand::AppendClientDebugInfoIfNeeded( 143 void DownloadUpdatesCommand::AppendClientDebugInfoIfNeeded(
110 sessions::SyncSession* session, 144 sessions::SyncSession* session,
111 DebugInfo* debug_info) { 145 DebugInfo* debug_info) {
112 // We want to send the debug info only once per sync cycle. Check if it has 146 // We want to send the debug info only once per sync cycle. Check if it has
113 // already been sent. 147 // already been sent.
114 if (!session->status_controller().debug_info_sent()) { 148 if (!session->status_controller().debug_info_sent()) {
115 DVLOG(1) << "Sending client debug info ..."; 149 DVLOG(1) << "Sending client debug info ...";
116 // could be null in some unit tests. 150 // could be null in some unit tests.
117 if (session->context()->debug_info_getter()) { 151 if (session->context()->debug_info_getter()) {
118 session->context()->debug_info_getter()->GetAndClearDebugInfo( 152 session->context()->debug_info_getter()->GetAndClearDebugInfo(
119 debug_info); 153 debug_info);
120 } 154 }
121 session->mutable_status_controller()->set_debug_info_sent(); 155 session->mutable_status_controller()->set_debug_info_sent();
122 } 156 }
123 } 157 }
124 158
125 } // namespace syncer 159 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698