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

Unified Diff: third_party/libaddressinput/chromium/chrome_storage_impl.cc

Issue 98623005: rAc i18n: implement storage interface for libaddressinput (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scopedvector Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/chrome_storage_impl.cc
diff --git a/third_party/libaddressinput/chromium/chrome_storage_impl.cc b/third_party/libaddressinput/chromium/chrome_storage_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae84c4b1cd0c893e8b623a16cc676b92df01b19c
--- /dev/null
+++ b/third_party/libaddressinput/chromium/chrome_storage_impl.cc
@@ -0,0 +1,70 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/libaddressinput/chromium/chrome_storage_impl.h"
+
+#include "base/prefs/writeable_pref_store.h"
+#include "base/values.h"
+
+ChromeStorageImpl::ChromeStorageImpl(WriteablePrefStore* store)
+ : backing_store_(store),
+ scoped_observer_(this) {
+ scoped_observer_.Add(backing_store_);
+}
+
+ChromeStorageImpl::~ChromeStorageImpl() {
+ // TODO(estade): this shouldn't be necessary.
+ for (std::vector<Request*>::iterator iter =
+ outstanding_requests_.begin();
+ iter != outstanding_requests_.end(); ++iter) {
+ (*(*iter)->callback)(false, (*iter)->key, std::string());
+ }
+}
+
+void ChromeStorageImpl::Put(const std::string& key, const std::string& data) {
+ backing_store_->SetValue(key, new base::StringValue(data));
+}
+
+void ChromeStorageImpl::Get(
+ const std::string& key,
+ scoped_ptr<Storage::Callback> data_ready) const {
+ // |Get()| should not be const, so this is just a thunk that fixes that.
+ const_cast<ChromeStorageImpl*>(this)->DoGet(key, data_ready.Pass());
+}
+
+void ChromeStorageImpl::OnPrefValueChanged(const std::string& key) {}
+
+void ChromeStorageImpl::OnInitializationCompleted(bool succeeded) {
+ for (std::vector<Request*>::iterator iter =
+ outstanding_requests_.begin();
+ iter != outstanding_requests_.end(); ++iter) {
+ DoGet((*iter)->key, (*iter)->callback.Pass());
+ }
+
+ outstanding_requests_.clear();
+}
+
+void ChromeStorageImpl::DoGet(
+ const std::string& key,
+ scoped_ptr<Storage::Callback> data_ready) {
+ if (!backing_store_->IsInitializationComplete()) {
+ outstanding_requests_.push_back(
+ new Request(key, data_ready.Pass()));
+ return;
+ }
+
+ const base::Value* value;
+ std::string result;
+ if (backing_store_->GetValue(key, &value) &&
+ value->GetAsString(&result)) {
+ (*data_ready)(true, key, result);
+ } else {
+ (*data_ready)(false, key, std::string());
+ }
+}
+
+ChromeStorageImpl::Request::Request(const std::string& key,
+ scoped_ptr<Storage::Callback> callback)
+ : key(key),
+ callback(callback.Pass()) {}

Powered by Google App Engine
This is Rietveld 408576698