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

Side by Side Diff: chrome/browser/sync/internal_api/write_node.cc

Issue 7795002: [Sync] Gracefully handle writing to a node when the cryptographer is not ready. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 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
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/sync/internal_api/write_node.h" 5 #include "chrome/browser/sync/internal_api/write_node.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/sync/engine/nigori_util.h" 10 #include "chrome/browser/sync/engine/nigori_util.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const sync_pb::EntitySpecifics& new_specifics, 49 const sync_pb::EntitySpecifics& new_specifics,
50 syncable::MutableEntry* entry) { 50 syncable::MutableEntry* entry) {
51 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); 51 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics);
52 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); 52 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE);
53 syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes(); 53 syncable::ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes();
54 54
55 sync_pb::EntitySpecifics generated_specifics; 55 sync_pb::EntitySpecifics generated_specifics;
56 if (type == syncable::PASSWORDS || // Has own encryption scheme. 56 if (type == syncable::PASSWORDS || // Has own encryption scheme.
57 type == syncable::NIGORI || // Encrypted separately. 57 type == syncable::NIGORI || // Encrypted separately.
58 encrypted_types.count(type) == 0 || 58 encrypted_types.count(type) == 0 ||
59 new_specifics.has_encrypted()) { 59 new_specifics.has_encrypted() ||
60 // No encryption required. 60 !cryptographer->is_initialized()) {
61 // No encryption required or we are unable to encrypt.
61 generated_specifics.CopyFrom(new_specifics); 62 generated_specifics.CopyFrom(new_specifics);
62 } else { 63 } else {
63 // Encrypt new_specifics into generated_specifics. 64 // Encrypt new_specifics into generated_specifics.
64 if (VLOG_IS_ON(2)) { 65 if (VLOG_IS_ON(2)) {
65 scoped_ptr<DictionaryValue> value(entry->ToValue()); 66 scoped_ptr<DictionaryValue> value(entry->ToValue());
66 std::string info; 67 std::string info;
67 base::JSONWriter::Write(value.get(), true, &info); 68 base::JSONWriter::Write(value.get(), true, &info);
68 VLOG(2) << "Encrypting specifics of type " 69 VLOG(2) << "Encrypting specifics of type "
69 << syncable::ModelTypeToString(type) 70 << syncable::ModelTypeToString(type)
70 << " with content: " 71 << " with content: "
71 << info; 72 << info;
72 } 73 }
73 if (!cryptographer->is_initialized())
74 return false;
75 syncable::AddDefaultExtensionValue(type, &generated_specifics); 74 syncable::AddDefaultExtensionValue(type, &generated_specifics);
76 if (!cryptographer->Encrypt(new_specifics, 75 if (!cryptographer->Encrypt(new_specifics,
77 generated_specifics.mutable_encrypted())) { 76 generated_specifics.mutable_encrypted())) {
78 NOTREACHED() << "Could not encrypt data for node of type " 77 NOTREACHED() << "Could not encrypt data for node of type "
79 << syncable::ModelTypeToString(type); 78 << syncable::ModelTypeToString(type);
80 return false; 79 return false;
81 } 80 }
82 } 81 }
83 82
84 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS); 83 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS);
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics(); 530 sync_pb::BookmarkSpecifics new_value = GetBookmarkSpecifics();
532 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size()); 531 new_value.set_favicon(bytes.empty() ? NULL : &bytes[0], bytes.size());
533 SetBookmarkSpecifics(new_value); 532 SetBookmarkSpecifics(new_value);
534 } 533 }
535 534
536 void WriteNode::MarkForSyncing() { 535 void WriteNode::MarkForSyncing() {
537 syncable::MarkForSyncing(entry_); 536 syncable::MarkForSyncing(entry_);
538 } 537 }
539 538
540 } // namespace sync_api 539 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698