| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/stringprintf.h" | 5 #include "base/stringprintf.h" |
| 6 #include "chrome/browser/extensions/web_intent_callbacks.h" | 6 #include "chrome/browser/extensions/web_intent_callbacks.h" |
| 7 #include "chrome/browser/profiles/profile_dependency_manager.h" | 7 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 // SourceObserver is a subclass of WebContentsObserver that is instantiated | 24 // SourceObserver is a subclass of WebContentsObserver that is instantiated |
| 25 // on RegisterCallback to wait for the source WebContents to be destroyed. | 25 // on RegisterCallback to wait for the source WebContents to be destroyed. |
| 26 // If it is destroyed, this automatically clears the callback from pending_. | 26 // If it is destroyed, this automatically clears the callback from pending_. |
| 27 class WebIntentCallbacks::SourceObserver : content::WebContentsObserver { | 27 class WebIntentCallbacks::SourceObserver : content::WebContentsObserver { |
| 28 public: | 28 public: |
| 29 SourceObserver(content::WebContents* web_contents, | 29 SourceObserver(content::WebContents* web_contents, |
| 30 WebIntentCallbacks* callbacks, | 30 WebIntentCallbacks* callbacks, |
| 31 const std::string key) | 31 const std::string& key) |
| 32 : content::WebContentsObserver(web_contents), | 32 : content::WebContentsObserver(web_contents), |
| 33 callbacks_(callbacks), | 33 callbacks_(callbacks), |
| 34 key_(key) {} | 34 key_(key) {} |
| 35 virtual ~SourceObserver() {} | 35 virtual ~SourceObserver() {} |
| 36 | 36 |
| 37 // Implement WebContentsObserver | 37 // Implement WebContentsObserver |
| 38 virtual void WebContentsDestroyed(content::WebContents* web_contents) | 38 virtual void WebContentsDestroyed(content::WebContents* web_contents) |
| 39 OVERRIDE { | 39 OVERRIDE { |
| 40 content::WebIntentsDispatcher* dispatcher = | 40 content::WebIntentsDispatcher* dispatcher = |
| 41 callbacks_->GetAndClear(key_); | 41 callbacks_->GetAndClear(key_); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 return id; | 82 return id; |
| 83 } | 83 } |
| 84 | 84 |
| 85 content::WebIntentsDispatcher* WebIntentCallbacks::RetrieveCallback( | 85 content::WebIntentsDispatcher* WebIntentCallbacks::RetrieveCallback( |
| 86 const Extension* extension, int id) { | 86 const Extension* extension, int id) { |
| 87 std::string key = GetKey(extension, id); | 87 std::string key = GetKey(extension, id); |
| 88 return GetAndClear(key); | 88 return GetAndClear(key); |
| 89 } | 89 } |
| 90 | 90 |
| 91 content::WebIntentsDispatcher* WebIntentCallbacks::GetAndClear( | 91 content::WebIntentsDispatcher* WebIntentCallbacks::GetAndClear( |
| 92 std::string key) { | 92 const std::string& key) { |
| 93 if (!pending_.count(key)) | 93 if (!pending_.count(key)) |
| 94 return NULL; | 94 return NULL; |
| 95 | 95 |
| 96 content::WebIntentsDispatcher* dispatcher = pending_[key]; | 96 content::WebIntentsDispatcher* dispatcher = pending_[key]; |
| 97 pending_.erase(key); | 97 pending_.erase(key); |
| 98 return dispatcher; | 98 return dispatcher; |
| 99 } | 99 } |
| 100 | 100 |
| 101 /////////////////////////////////////////////////////////////////////////////// | 101 /////////////////////////////////////////////////////////////////////////////// |
| 102 // Factory boilerplate | 102 // Factory boilerplate |
| (...skipping 16 matching lines...) Expand all Loading... |
| 119 | 119 |
| 120 WebIntentCallbacks::Factory::~Factory() { | 120 WebIntentCallbacks::Factory::~Factory() { |
| 121 } | 121 } |
| 122 | 122 |
| 123 ProfileKeyedService* WebIntentCallbacks::Factory::BuildServiceInstanceFor( | 123 ProfileKeyedService* WebIntentCallbacks::Factory::BuildServiceInstanceFor( |
| 124 Profile* profile) const { | 124 Profile* profile) const { |
| 125 return new WebIntentCallbacks(); | 125 return new WebIntentCallbacks(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace extensions | 128 } // namespace extensions |
| OLD | NEW |