OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/printing/printers_sync_bridge.h" | 5 #include "chrome/browser/chromeos/printing/printers_sync_bridge.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 : owner_(owner), weak_ptr_factory_(this) { | 79 : owner_(owner), weak_ptr_factory_(this) { |
80 callback.Run(base::Bind(&StoreProxy::OnStoreCreated, | 80 callback.Run(base::Bind(&StoreProxy::OnStoreCreated, |
81 weak_ptr_factory_.GetWeakPtr())); | 81 weak_ptr_factory_.GetWeakPtr())); |
82 } | 82 } |
83 | 83 |
84 // Returns true if the store has been initialized. | 84 // Returns true if the store has been initialized. |
85 bool Ready() { return store_.get() != nullptr; } | 85 bool Ready() { return store_.get() != nullptr; } |
86 | 86 |
87 // Returns a new WriteBatch. | 87 // Returns a new WriteBatch. |
88 std::unique_ptr<ModelTypeStore::WriteBatch> CreateWriteBatch() { | 88 std::unique_ptr<ModelTypeStore::WriteBatch> CreateWriteBatch() { |
89 CHECK(store_); | 89 DCHECK(store_); |
90 return store_->CreateWriteBatch(); | 90 return store_->CreateWriteBatch(); |
91 } | 91 } |
92 | 92 |
93 // Commits writes to the database and updates metadata. | 93 // Commits writes to the database and updates metadata. |
94 void Commit(std::unique_ptr<ModelTypeStore::WriteBatch> batch) { | 94 void Commit(std::unique_ptr<ModelTypeStore::WriteBatch> batch) { |
95 CHECK(store_); | 95 DCHECK(store_); |
96 store_->CommitWriteBatch( | 96 store_->CommitWriteBatch( |
97 std::move(batch), | 97 std::move(batch), |
98 base::Bind(&StoreProxy::OnCommit, weak_ptr_factory_.GetWeakPtr())); | 98 base::Bind(&StoreProxy::OnCommit, weak_ptr_factory_.GetWeakPtr())); |
99 } | 99 } |
100 | 100 |
101 private: | 101 private: |
102 // Callback for ModelTypeStore initialization. | 102 // Callback for ModelTypeStore initialization. |
103 void OnStoreCreated(Result result, std::unique_ptr<ModelTypeStore> store) { | 103 void OnStoreCreated(Result result, std::unique_ptr<ModelTypeStore> store) { |
104 if (result == Result::SUCCESS) { | 104 if (result == Result::SUCCESS) { |
105 store_ = std::move(store); | 105 store_ = std::move(store); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 const std::string& id) const { | 349 const std::string& id) const { |
350 auto iter = all_data_.find(id); | 350 auto iter = all_data_.find(id); |
351 if (iter == all_data_.end()) { | 351 if (iter == all_data_.end()) { |
352 return {}; | 352 return {}; |
353 } | 353 } |
354 | 354 |
355 return {*iter->second}; | 355 return {*iter->second}; |
356 } | 356 } |
357 | 357 |
358 } // namespace chromeos | 358 } // namespace chromeos |
OLD | NEW |