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 "chrome/browser/download/download_extension_api.h" | 5 #include "chrome/browser/download/download_extension_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cctype> | 8 #include <cctype> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/string16.h" | 20 #include "base/string16.h" |
20 #include "base/string_util.h" | 21 #include "base/string_util.h" |
21 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 json->SetInteger(kTotalBytesKey, item->GetTotalBytes()); | 468 json->SetInteger(kTotalBytesKey, item->GetTotalBytes()); |
468 if (item->GetState() == DownloadItem::INTERRUPTED) | 469 if (item->GetState() == DownloadItem::INTERRUPTED) |
469 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason())); | 470 json->SetInteger(kErrorKey, static_cast<int>(item->GetLastReason())); |
470 // TODO(benjhayden): Implement endTime and fileSize. | 471 // TODO(benjhayden): Implement endTime and fileSize. |
471 // json->SetInteger(kEndTimeKey, -1); | 472 // json->SetInteger(kEndTimeKey, -1); |
472 json->SetInteger(kFileSizeKey, item->GetTotalBytes()); | 473 json->SetInteger(kFileSizeKey, item->GetTotalBytes()); |
473 return json; | 474 return json; |
474 } | 475 } |
475 } // anonymous namespace | 476 } // anonymous namespace |
476 | 477 |
477 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter( | 478 ExtensionDownloadsEventRouter::ExtensionDownloadsEventRouter(Profile* profile) |
478 Profile* profile) | |
479 : profile_(profile), | 479 : profile_(profile), |
480 manager_( | 480 manager_(NULL) { |
481 profile ? | |
482 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager() : | |
483 NULL) { | |
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
485 DCHECK(profile_); | 482 DCHECK(profile_); |
486 DCHECK(manager_); | 483 DownloadServiceFactory::GetForProfile(profile)->OnManagerCreated(base::Bind( |
Randy Smith (Not in Mondays)
2011/12/06 17:12:41
nit: Add a comment explaining what's going on here
benjhayden
2011/12/06 18:45:06
Done.
| |
484 &ExtensionDownloadsEventRouter::Init, base::Unretained(this))); | |
485 } | |
486 | |
487 void ExtensionDownloadsEventRouter::Init(DownloadManager* manager) { | |
488 DCHECK(manager_ == NULL); | |
489 manager_ = manager; | |
487 manager_->AddObserver(this); | 490 manager_->AddObserver(this); |
488 } | 491 } |
489 | 492 |
490 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { | 493 ExtensionDownloadsEventRouter::~ExtensionDownloadsEventRouter() { |
491 if (manager_ != NULL) | 494 if (manager_ != NULL) |
492 manager_->RemoveObserver(this); | 495 manager_->RemoveObserver(this); |
493 } | 496 } |
494 | 497 |
495 void ExtensionDownloadsEventRouter::ModelChanged() { | 498 void ExtensionDownloadsEventRouter::ModelChanged() { |
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 ListValue args; | 549 ListValue args; |
547 args.Append(arg); | 550 args.Append(arg); |
548 std::string json_args; | 551 std::string json_args; |
549 base::JSONWriter::Write(&args, false, &json_args); | 552 base::JSONWriter::Write(&args, false, &json_args); |
550 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 553 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
551 event_name, | 554 event_name, |
552 json_args, | 555 json_args, |
553 profile_, | 556 profile_, |
554 GURL()); | 557 GURL()); |
555 } | 558 } |
OLD | NEW |