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

Side by Side Diff: chrome/browser/ui/webui/downloads_dom_handler.cc

Issue 10154004: re-use WebUIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WeakPtr solution Created 8 years, 8 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 | Annotate | Revision Log
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/ui/webui/downloads_dom_handler.h" 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 event, 85 event,
86 DOWNLOADS_DOM_EVENT_MAX); 86 DOWNLOADS_DOM_EVENT_MAX);
87 } 87 }
88 88
89 } // namespace 89 } // namespace
90 90
91 DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm) 91 DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm)
92 : search_text_(), 92 : search_text_(),
93 download_manager_(dlm), 93 download_manager_(dlm),
94 original_profile_download_manager_(NULL), 94 original_profile_download_manager_(NULL),
95 initialized_(false),
95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 96 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
96 // Create our fileicon data source. 97 // Create our fileicon data source.
97 Profile* profile = Profile::FromBrowserContext(dlm->GetBrowserContext()); 98 Profile* profile = Profile::FromBrowserContext(dlm->GetBrowserContext());
98 ChromeURLDataManager::AddDataSource(profile, new FileIconSource()); 99 ChromeURLDataManager::AddDataSource(profile, new FileIconSource());
99 100
100 // Figure out our parent DownloadManager, if any. 101 // Figure out our parent DownloadManager, if any.
101 Profile* original_profile = profile->GetOriginalProfile(); 102 Profile* original_profile = profile->GetOriginalProfile();
102 if (original_profile != profile) { 103 if (original_profile != profile) {
103 original_profile_download_manager_ = DownloadServiceFactory::GetForProfile( 104 original_profile_download_manager_ = DownloadServiceFactory::GetForProfile(
104 original_profile)->GetDownloadManager(); 105 original_profile)->GetDownloadManager();
105 } 106 }
106 } 107 }
107 108
108 DownloadsDOMHandler::~DownloadsDOMHandler() { 109 DownloadsDOMHandler::~DownloadsDOMHandler() {
109 ClearDownloadItems(); 110 ClearDownloadItems();
110 download_manager_->RemoveObserver(this); 111 download_manager_->RemoveObserver(this);
111 if (original_profile_download_manager_) 112 if (original_profile_download_manager_)
112 original_profile_download_manager_->RemoveObserver(this); 113 original_profile_download_manager_->RemoveObserver(this);
113 } 114 }
114 115
115 // DownloadsDOMHandler, public: ----------------------------------------------- 116 // DownloadsDOMHandler, public: -----------------------------------------------
116 117
117 void DownloadsDOMHandler::OnPageLoaded(const base::ListValue* args) { 118 void DownloadsDOMHandler::OnPageLoaded(const base::ListValue* args) {
119 if (initialized_)
120 return;
121 initialized_ = true;
122
118 download_manager_->AddObserver(this); 123 download_manager_->AddObserver(this);
119 if (original_profile_download_manager_) 124 if (original_profile_download_manager_)
120 original_profile_download_manager_->AddObserver(this); 125 original_profile_download_manager_->AddObserver(this);
121 } 126 }
122 127
123 void DownloadsDOMHandler::RegisterMessages() { 128 void DownloadsDOMHandler::RegisterMessages() {
124 web_ui()->RegisterMessageCallback("onPageLoaded", 129 web_ui()->RegisterMessageCallback("onPageLoaded",
125 base::Bind(&DownloadsDOMHandler::OnPageLoaded, 130 base::Bind(&DownloadsDOMHandler::OnPageLoaded,
126 base::Unretained(this))); 131 base::Unretained(this)));
127 web_ui()->RegisterMessageCallback("getDownloads", 132 web_ui()->RegisterMessageCallback("getDownloads",
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 407 }
403 408
404 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( 409 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue(
405 const ListValue* args) { 410 const ListValue* args) {
406 int id; 411 int id;
407 if (ExtractIntegerValue(args, &id)) { 412 if (ExtractIntegerValue(args, &id)) {
408 return GetDownloadById(id); 413 return GetDownloadById(id);
409 } 414 }
410 return NULL; 415 return NULL;
411 } 416 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/downloads_dom_handler.h ('k') | chrome/browser/ui/webui/gpu_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698