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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_api.cc

Issue 2702503003: [Dial] Refactor DialRegistry and DeviceDescriptionFetcher so they can be used by MediaSinkService (Closed)
Patch Set: resolve code review comments from Derek Created 3 years, 9 months 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 unified diff | Download patch
OLDNEW
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 "chrome/browser/extensions/api/dial/dial_api.h" 5 #include "chrome/browser/extensions/api/dial/dial_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 EventRouter::Get(profile)->RegisterObserver( 49 EventRouter::Get(profile)->RegisterObserver(
50 this, api::dial::OnDeviceList::kEventName); 50 this, api::dial::OnDeviceList::kEventName);
51 } 51 }
52 52
53 DialAPI::~DialAPI() {} 53 DialAPI::~DialAPI() {}
54 54
55 DialRegistry* DialAPI::dial_registry() { 55 DialRegistry* DialAPI::dial_registry() {
56 DCHECK_CURRENTLY_ON(BrowserThread::IO); 56 DCHECK_CURRENTLY_ON(BrowserThread::IO);
57 if (!dial_registry_.get()) { 57 if (!dial_registry_.get()) {
58 dial_registry_.reset(new DialRegistry( 58 dial_registry_.reset(new DialRegistry(
59 this, TimeDelta::FromSeconds(kDialRefreshIntervalSecs), 59 TimeDelta::FromSeconds(kDialRefreshIntervalSecs),
60 TimeDelta::FromSeconds(kDialExpirationSecs), kDialMaxDevices)); 60 TimeDelta::FromSeconds(kDialExpirationSecs), kDialMaxDevices));
61 dial_registry_->RegisterObserver(this);
61 if (test_device_data_) { 62 if (test_device_data_) {
62 dial_registry_->AddDeviceForTest(*test_device_data_); 63 dial_registry_->AddDeviceForTest(*test_device_data_);
63 } 64 }
64 } 65 }
65 return dial_registry_.get(); 66 return dial_registry_.get();
66 } 67 }
67 68
68 void DialAPI::OnListenerAdded(const EventListenerInfo& details) { 69 void DialAPI::OnListenerAdded(const EventListenerInfo& details) {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(BrowserThread::UI);
70 BrowserThread::PostTask( 71 BrowserThread::PostTask(
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return; 224 return;
224 } 225 }
225 226
226 if (dial_->test_device_data_ && dial_->test_device_description_ && 227 if (dial_->test_device_data_ && dial_->test_device_description_ &&
227 dial_->test_device_data_->device_description_url() == url) { 228 dial_->test_device_data_->device_description_url() == url) {
228 OnFetchComplete(*(dial_->test_device_description_)); 229 OnFetchComplete(*(dial_->test_device_description_));
229 return; 230 return;
230 } 231 }
231 232
232 device_description_fetcher_ = base::MakeUnique<DeviceDescriptionFetcher>( 233 device_description_fetcher_ = base::MakeUnique<DeviceDescriptionFetcher>(
233 url, Profile::FromBrowserContext(browser_context()), 234 url, Profile::FromBrowserContext(browser_context())->GetRequestContext(),
234 base::BindOnce(&DialFetchDeviceDescriptionFunction::OnFetchComplete, 235 base::BindOnce(&DialFetchDeviceDescriptionFunction::OnFetchComplete,
235 this), 236 this),
236 base::BindOnce(&DialFetchDeviceDescriptionFunction::OnFetchError, this)); 237 base::BindOnce(&DialFetchDeviceDescriptionFunction::OnFetchError, this));
237 238
238 device_description_fetcher_->Start(); 239 device_description_fetcher_->Start();
239 } 240 }
240 241
241 void DialFetchDeviceDescriptionFunction::OnFetchComplete( 242 void DialFetchDeviceDescriptionFunction::OnFetchComplete(
242 const api::dial::DialDeviceDescriptionData& result) { 243 const api::dial::DialDeviceDescriptionData& result) {
243 // Destroy the DeviceDescriptionFetcher since it still contains a reference 244 // Destroy the DeviceDescriptionFetcher since it still contains a reference
(...skipping 10 matching lines...) Expand all
254 void DialFetchDeviceDescriptionFunction::OnFetchError( 255 void DialFetchDeviceDescriptionFunction::OnFetchError(
255 const std::string& message) { 256 const std::string& message) {
256 // Destroy the DeviceDescriptionFetcher since it still contains a reference 257 // Destroy the DeviceDescriptionFetcher since it still contains a reference
257 // to |this| in its un-invoked callback. 258 // to |this| in its un-invoked callback.
258 device_description_fetcher_.reset(); 259 device_description_fetcher_.reset();
259 SetError(message); 260 SetError(message);
260 SendResponse(false); 261 SendResponse(false);
261 } 262 }
262 263
263 } // namespace extensions 264 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698