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

Side by Side Diff: chrome/browser/dom_ui/slideshow_ui.cc

Issue 5710002: Create base::WorkerPoolJob. Use it for HostResolverImpl and DirectoryLister. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minimize the header dependency. Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/slideshow_ui.h" 5 #include "chrome/browser/dom_ui/slideshow_ui.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return "text/html"; 51 return "text/html";
52 } 52 }
53 53
54 private: 54 private:
55 ~SlideshowUIHTMLSource() {} 55 ~SlideshowUIHTMLSource() {}
56 56
57 DISALLOW_COPY_AND_ASSIGN(SlideshowUIHTMLSource); 57 DISALLOW_COPY_AND_ASSIGN(SlideshowUIHTMLSource);
58 }; 58 };
59 59
60 // The handler for Javascript messages related to the "slideshow" view. 60 // The handler for Javascript messages related to the "slideshow" view.
61 class SlideshowHandler : public net::DirectoryLister::DirectoryListerDelegate, 61 class SlideshowHandler : public net::DirectoryLister::Delegate,
62 public DOMMessageHandler, 62 public DOMMessageHandler,
63 public base::SupportsWeakPtr<SlideshowHandler> { 63 public base::SupportsWeakPtr<SlideshowHandler> {
64 public: 64 public:
65 SlideshowHandler(); 65 SlideshowHandler();
66 virtual ~SlideshowHandler(); 66 virtual ~SlideshowHandler();
67 67
68 // Init work after Attach. 68 // Init work after Attach.
69 void Init(); 69 void Init();
70 70
71 // DirectoryLister::DirectoryListerDelegate methods: 71 // DirectoryLister::Delegate methods:
72 virtual void OnListFile( 72 virtual void OnListFile(const net::DirectoryLister::Data& data);
73 const net::DirectoryLister::DirectoryListerData& data);
74 virtual void OnListDone(int error); 73 virtual void OnListDone(int error);
75 74
76 // DOMMessageHandler implementation. 75 // DOMMessageHandler implementation.
77 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); 76 virtual DOMMessageHandler* Attach(DOMUI* dom_ui);
78 virtual void RegisterMessages(); 77 virtual void RegisterMessages();
79 78
80 void GetChildrenForPath(const FilePath& path, bool is_refresh); 79 void GetChildrenForPath(const FilePath& path, bool is_refresh);
81 80
82 // Callback for the "getChildren" message. 81 // Callback for the "getChildren" message.
83 void HandleGetChildren(const ListValue* args); 82 void HandleGetChildren(const ListValue* args);
84 83
85 void HandleRefreshDirectory(const ListValue* args); 84 void HandleRefreshDirectory(const ListValue* args);
86 85
87 private: 86 private:
88 bool PathIsImageFile(const char* filename); 87 bool PathIsImageFile(const char* filename);
89 88
90 scoped_ptr<ListValue> filelist_value_; 89 scoped_ptr<ListValue> filelist_value_;
91 FilePath currentpath_; 90 FilePath currentpath_;
92 FilePath originalpath_; 91 FilePath originalpath_;
93 Profile* profile_; 92 Profile* profile_;
94 int counter_; 93 int counter_;
95 int currentOffset_; 94 int currentOffset_;
96 scoped_refptr<net::DirectoryLister> lister_; 95 scoped_ptr<net::DirectoryLister> lister_;
97 bool is_refresh_; 96 bool is_refresh_;
98 97
99 DISALLOW_COPY_AND_ASSIGN(SlideshowHandler); 98 DISALLOW_COPY_AND_ASSIGN(SlideshowHandler);
100 }; 99 };
101 100
102 //////////////////////////////////////////////////////////////////////////////// 101 ////////////////////////////////////////////////////////////////////////////////
103 // 102 //
104 // SlideshowHTMLSource 103 // SlideshowHTMLSource
105 // 104 //
106 //////////////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////////////
(...skipping 24 matching lines...) Expand all
131 } 130 }
132 131
133 //////////////////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////////////////
134 // 133 //
135 // SlideshowHandler 134 // SlideshowHandler
136 // 135 //
137 //////////////////////////////////////////////////////////////////////////////// 136 ////////////////////////////////////////////////////////////////////////////////
138 SlideshowHandler::SlideshowHandler() 137 SlideshowHandler::SlideshowHandler()
139 : profile_(NULL), 138 : profile_(NULL),
140 is_refresh_(false) { 139 is_refresh_(false) {
141 lister_ = NULL;
142 } 140 }
143 141
144 SlideshowHandler::~SlideshowHandler() { 142 SlideshowHandler::~SlideshowHandler() {}
145 if (lister_.get()) {
146 lister_->Cancel();
147 lister_->set_delegate(NULL);
148 }
149 }
150 143
151 DOMMessageHandler* SlideshowHandler::Attach(DOMUI* dom_ui) { 144 DOMMessageHandler* SlideshowHandler::Attach(DOMUI* dom_ui) {
152 // Create our favicon data source. 145 // Create our favicon data source.
153 BrowserThread::PostTask( 146 BrowserThread::PostTask(
154 BrowserThread::IO, FROM_HERE, 147 BrowserThread::IO, FROM_HERE,
155 NewRunnableMethod( 148 NewRunnableMethod(
156 ChromeURLDataManager::GetInstance(), 149 ChromeURLDataManager::GetInstance(),
157 &ChromeURLDataManager::AddDataSource, 150 &ChromeURLDataManager::AddDataSource,
158 make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile())))); 151 make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile()))));
159 profile_ = dom_ui->GetProfile(); 152 profile_ = dom_ui->GetProfile();
(...skipping 15 matching lines...) Expand all
175 std::string path = WideToUTF8(ExtractStringValue(args)); 168 std::string path = WideToUTF8(ExtractStringValue(args));
176 GetChildrenForPath(FilePath(path), true); 169 GetChildrenForPath(FilePath(path), true);
177 #endif 170 #endif
178 } 171 }
179 172
180 void SlideshowHandler::GetChildrenForPath(const FilePath& path, 173 void SlideshowHandler::GetChildrenForPath(const FilePath& path,
181 bool is_refresh) { 174 bool is_refresh) {
182 filelist_value_.reset(new ListValue()); 175 filelist_value_.reset(new ListValue());
183 currentpath_ = path; 176 currentpath_ = path;
184 177
185 if (lister_.get()) { 178 lister_.reset();
186 lister_->Cancel();
187 lister_->set_delegate(NULL);
188 lister_ = NULL;
189 }
190 179
191 is_refresh_ = is_refresh; 180 is_refresh_ = is_refresh;
192 if (file_util::EnsureEndsWithSeparator(&currentpath_) && 181 if (file_util::EnsureEndsWithSeparator(&currentpath_) &&
193 currentpath_.IsAbsolute()) { 182 currentpath_.IsAbsolute()) {
194 lister_ = new net::DirectoryLister(currentpath_, this); 183 lister_.reset(new net::DirectoryLister(currentpath_, this));
195 } else { 184 } else {
196 originalpath_ = currentpath_; 185 originalpath_ = currentpath_;
197 currentpath_ = currentpath_.DirName(); 186 currentpath_ = currentpath_.DirName();
198 lister_ = new net::DirectoryLister(currentpath_, this); 187 lister_.reset(new net::DirectoryLister(currentpath_, this));
199 } 188 }
200 counter_ = 0; 189 counter_ = 0;
201 currentOffset_ = -1; 190 currentOffset_ = -1;
202 lister_->Start(); 191 lister_->Start();
203 } 192 }
204 193
205 void SlideshowHandler::HandleGetChildren(const ListValue* args) { 194 void SlideshowHandler::HandleGetChildren(const ListValue* args) {
206 #if defined(OS_CHROMEOS) 195 #if defined(OS_CHROMEOS)
207 filelist_value_.reset(new ListValue()); 196 filelist_value_.reset(new ListValue());
208 std::string path = WideToUTF8(ExtractStringValue(args)); 197 std::string path = WideToUTF8(ExtractStringValue(args));
(...skipping 12 matching lines...) Expand all
221 ext == ".gif") { 210 ext == ".gif") {
222 return true; 211 return true;
223 } else { 212 } else {
224 return false; 213 return false;
225 } 214 }
226 #else 215 #else
227 return false; 216 return false;
228 #endif 217 #endif
229 } 218 }
230 219
231 void SlideshowHandler::OnListFile( 220 void SlideshowHandler::OnListFile(const net::DirectoryLister::Data& data) {
232 const net::DirectoryLister::DirectoryListerData& data) {
233 #if defined(OS_CHROMEOS) 221 #if defined(OS_CHROMEOS)
234 if (data.info.filename[0] == '.') { 222 if (data.info.filename[0] == '.') {
235 return; 223 return;
236 } 224 }
237 if (!PathIsImageFile(data.info.filename.c_str())) { 225 if (!PathIsImageFile(data.info.filename.c_str())) {
238 return; 226 return;
239 } 227 }
240 228
241 DictionaryValue* file_value = new DictionaryValue(); 229 DictionaryValue* file_value = new DictionaryValue();
242 230
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 SlideshowUIHTMLSource* html_source = new SlideshowUIHTMLSource(); 273 SlideshowUIHTMLSource* html_source = new SlideshowUIHTMLSource();
286 274
287 // Set up the chrome://slideshow/ source. 275 // Set up the chrome://slideshow/ source.
288 BrowserThread::PostTask( 276 BrowserThread::PostTask(
289 BrowserThread::IO, FROM_HERE, 277 BrowserThread::IO, FROM_HERE,
290 NewRunnableMethod( 278 NewRunnableMethod(
291 ChromeURLDataManager::GetInstance(), 279 ChromeURLDataManager::GetInstance(),
292 &ChromeURLDataManager::AddDataSource, 280 &ChromeURLDataManager::AddDataSource,
293 make_scoped_refptr(html_source))); 281 make_scoped_refptr(html_source)));
294 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698