OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "webkit/appcache/view_appcache_internals_job.h" | 8 #include "webkit/appcache/view_appcache_internals_job.h" |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/weak_ptr.h" |
14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "net/base/escape.h" | 19 #include "net/base/escape.h" |
19 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
20 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_simple_job.h" | 23 #include "net/url_request/url_request_simple_job.h" |
23 #include "net/url_request/view_cache_helper.h" | 24 #include "net/url_request/view_cache_helper.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 BaseInternalsJob(net::URLRequest* request, AppCacheService* service) | 310 BaseInternalsJob(net::URLRequest* request, AppCacheService* service) |
310 : URLRequestSimpleJob(request), appcache_service_(service) {} | 311 : URLRequestSimpleJob(request), appcache_service_(service) {} |
311 | 312 |
312 AppCacheService* appcache_service_; | 313 AppCacheService* appcache_service_; |
313 }; | 314 }; |
314 | 315 |
315 // Job that lists all appcaches in the system. | 316 // Job that lists all appcaches in the system. |
316 class MainPageJob : public BaseInternalsJob { | 317 class MainPageJob : public BaseInternalsJob { |
317 public: | 318 public: |
318 MainPageJob(net::URLRequest* request, AppCacheService* service) | 319 MainPageJob(net::URLRequest* request, AppCacheService* service) |
319 : BaseInternalsJob(request, service) {} | 320 : BaseInternalsJob(request, service), |
| 321 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 322 } |
320 | 323 |
321 virtual void Start() { | 324 virtual void Start() { |
322 DCHECK(request_); | 325 DCHECK(request_); |
323 info_collection_ = new AppCacheInfoCollection; | 326 info_collection_ = new AppCacheInfoCollection; |
324 gotinfo_complete_callback_ = | |
325 new net::CancelableOldCompletionCallback<MainPageJob>( | |
326 this, &MainPageJob::OnGotInfoComplete); | |
327 appcache_service_->GetAllAppCacheInfo( | 327 appcache_service_->GetAllAppCacheInfo( |
328 info_collection_, gotinfo_complete_callback_); | 328 info_collection_, base::Bind(&MainPageJob::OnGotInfoComplete, |
| 329 weak_factory_.GetWeakPtr())); |
329 } | 330 } |
330 | 331 |
331 // Produces a page containing the listing | 332 // Produces a page containing the listing |
332 virtual bool GetData(std::string* mime_type, | 333 virtual bool GetData(std::string* mime_type, |
333 std::string* charset, | 334 std::string* charset, |
334 std::string* out) const { | 335 std::string* out) const { |
335 mime_type->assign("text/html"); | 336 mime_type->assign("text/html"); |
336 charset->assign("UTF-8"); | 337 charset->assign("UTF-8"); |
337 | 338 |
338 out->clear(); | 339 out->clear(); |
(...skipping 14 matching lines...) Expand all Loading... |
353 std::sort(appcaches.begin(), appcaches.end(), SortByManifestUrl); | 354 std::sort(appcaches.begin(), appcaches.end(), SortByManifestUrl); |
354 | 355 |
355 GURL base_url = ClearQuery(request_->url()); | 356 GURL base_url = ClearQuery(request_->url()); |
356 EmitAppCacheInfoVector(base_url, appcache_service_, appcaches, out); | 357 EmitAppCacheInfoVector(base_url, appcache_service_, appcaches, out); |
357 } | 358 } |
358 EmitPageEnd(out); | 359 EmitPageEnd(out); |
359 return true; | 360 return true; |
360 } | 361 } |
361 | 362 |
362 private: | 363 private: |
363 virtual ~MainPageJob() { | 364 virtual ~MainPageJob() {} |
364 if (gotinfo_complete_callback_) | |
365 gotinfo_complete_callback_.release()->Cancel(); | |
366 } | |
367 | 365 |
368 void OnGotInfoComplete(int rv) { | 366 void OnGotInfoComplete(int rv) { |
369 gotinfo_complete_callback_ = NULL; | |
370 if (rv != net::OK) | 367 if (rv != net::OK) |
371 info_collection_ = NULL; | 368 info_collection_ = NULL; |
372 StartAsync(); | 369 StartAsync(); |
373 } | 370 } |
374 | 371 |
375 scoped_refptr<net::CancelableOldCompletionCallback<MainPageJob> > | 372 base::WeakPtrFactory<MainPageJob> weak_factory_; |
376 gotinfo_complete_callback_; | |
377 scoped_refptr<AppCacheInfoCollection> info_collection_; | 373 scoped_refptr<AppCacheInfoCollection> info_collection_; |
378 DISALLOW_COPY_AND_ASSIGN(MainPageJob); | 374 DISALLOW_COPY_AND_ASSIGN(MainPageJob); |
379 }; | 375 }; |
380 | 376 |
381 // Job that redirects back to the main appcache internals page. | 377 // Job that redirects back to the main appcache internals page. |
382 class RedirectToMainPageJob : public BaseInternalsJob { | 378 class RedirectToMainPageJob : public BaseInternalsJob { |
383 public: | 379 public: |
384 RedirectToMainPageJob(net::URLRequest* request, AppCacheService* service) | 380 RedirectToMainPageJob(net::URLRequest* request, AppCacheService* service) |
385 : BaseInternalsJob(request, service) {} | 381 : BaseInternalsJob(request, service) {} |
386 | 382 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return new ViewEntryJob(request, service, | 617 return new ViewEntryJob(request, service, |
622 DecodeBase64URL(tokens[0]), // manifest url | 618 DecodeBase64URL(tokens[0]), // manifest url |
623 DecodeBase64URL(tokens[1]), // entry url | 619 DecodeBase64URL(tokens[1]), // entry url |
624 response_id, group_id); | 620 response_id, group_id); |
625 } | 621 } |
626 | 622 |
627 return new RedirectToMainPageJob(request, service); | 623 return new RedirectToMainPageJob(request, service); |
628 } | 624 } |
629 | 625 |
630 } // namespace appcache | 626 } // namespace appcache |
OLD | NEW |