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

Unified Diff: ios/web/web_state/web_state_observer.cc

Issue 780873002: Upstream iOS web code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« ios/web/string_util_unittest.cc ('K') | « ios/web/string_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/web_state_observer.cc
diff --git a/ios/web/web_state/web_state_observer.cc b/ios/web/web_state/web_state_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5c1ab79fa2dc475c7004a9fabead8f937c0139b
--- /dev/null
+++ b/ios/web/web_state/web_state_observer.cc
@@ -0,0 +1,42 @@
+// Copyright 2014 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 "ios/web/public/web_state/web_state_observer.h"
+
+#include "ios/public/provider/web/web_state.h"
+#include "ios/web/public/load_committed_details.h"
+
+namespace web {
+
+WebStateObserver::WebStateObserver(ios::WebState* web_state)
+ : web_state_(nullptr) {
+ Observe(web_state);
+}
+
+WebStateObserver::WebStateObserver() : web_state_(nullptr) {
+}
+
+WebStateObserver::~WebStateObserver() {
+ if (web_state_)
+ web_state_->RemoveObserver(this);
+}
+
+void WebStateObserver::Observe(ios::WebState* web_state) {
+ if (web_state == web_state_) {
+ // Early exit to avoid infinite loops if we're in the middle of a callback.
+ return;
+ }
+ if (web_state_)
+ web_state_->RemoveObserver(this);
+ web_state_ = web_state;
+ if (web_state_)
+ web_state_->AddObserver(this);
+}
+
+void WebStateObserver::ResetWebState() {
+ web_state_->RemoveObserver(this);
+ web_state_ = NULL;
stuartmorgan 2014/12/04 23:22:58 Could you change this to nullptr?
+}
+
+} // namespace web
« ios/web/string_util_unittest.cc ('K') | « ios/web/string_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698