Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ios/web/public/web_state/web_state_observer.h" | |
| 6 | |
| 7 #include "ios/public/provider/web/web_state.h" | |
| 8 #include "ios/web/public/load_committed_details.h" | |
| 9 | |
| 10 namespace web { | |
| 11 | |
| 12 WebStateObserver::WebStateObserver(ios::WebState* web_state) | |
| 13 : web_state_(nullptr) { | |
| 14 Observe(web_state); | |
| 15 } | |
| 16 | |
| 17 WebStateObserver::WebStateObserver() : web_state_(nullptr) { | |
| 18 } | |
| 19 | |
| 20 WebStateObserver::~WebStateObserver() { | |
| 21 if (web_state_) | |
| 22 web_state_->RemoveObserver(this); | |
| 23 } | |
| 24 | |
| 25 void WebStateObserver::Observe(ios::WebState* web_state) { | |
| 26 if (web_state == web_state_) { | |
| 27 // Early exit to avoid infinite loops if we're in the middle of a callback. | |
| 28 return; | |
| 29 } | |
| 30 if (web_state_) | |
| 31 web_state_->RemoveObserver(this); | |
| 32 web_state_ = web_state; | |
| 33 if (web_state_) | |
| 34 web_state_->AddObserver(this); | |
| 35 } | |
| 36 | |
| 37 void WebStateObserver::ResetWebState() { | |
| 38 web_state_->RemoveObserver(this); | |
| 39 web_state_ = NULL; | |
|
stuartmorgan
2014/12/04 23:22:58
Could you change this to nullptr?
| |
| 40 } | |
| 41 | |
| 42 } // namespace web | |
| OLD | NEW |