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

Unified Diff: components/download/internal/model_impl.cc

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Moved stats out Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/download/internal/model_impl.cc
diff --git a/components/download/internal/model_impl.cc b/components/download/internal/model_impl.cc
index f061b5de07d4e6325450faf15124f2be323021d1..3d7e22cfda3ef2d669caba5d519176c042bffe52 100644
--- a/components/download/internal/model_impl.cc
+++ b/components/download/internal/model_impl.cc
@@ -7,18 +7,22 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "components/download/internal/entry.h"
+#include "components/download/internal/stats.h"
namespace download {
-ModelImpl::ModelImpl(Client* client, std::unique_ptr<Store> store)
- : client_(client), store_(std::move(store)), weak_ptr_factory_(this) {
- DCHECK(client_);
+ModelImpl::ModelImpl(std::unique_ptr<Store> store)
+ : client_(nullptr), store_(std::move(store)), weak_ptr_factory_(this) {
DCHECK(store_);
}
ModelImpl::~ModelImpl() = default;
-void ModelImpl::Initialize() {
+void ModelImpl::Initialize(Client* client) {
+ DCHECK(!client_);
+ client_ = client;
+ DCHECK(client_);
+
DCHECK(!store_->IsInitialized());
store_->Initialize(base::Bind(&ModelImpl::OnInitializedFinished,
weak_ptr_factory_.GetWeakPtr()));
@@ -79,26 +83,30 @@ Model::EntryList ModelImpl::PeekEntries() {
void ModelImpl::OnInitializedFinished(
bool success,
std::unique_ptr<std::vector<Entry>> entries) {
+ stats::LogModelOperationResult(stats::ModelAction::INITIALIZE, success);
+
if (!success) {
- client_->OnInitialized(false);
+ client_->OnModelReady(false);
return;
}
for (const auto& entry : *entries)
entries_.emplace(entry.guid, base::MakeUnique<Entry>(entry));
- client_->OnInitialized(true);
+ client_->OnModelReady(true);
}
void ModelImpl::OnDestroyFinished(bool success) {
store_.reset();
entries_.clear();
- client_->OnDestroyed(success);
+ client_->OnModelDestroyed(success);
}
void ModelImpl::OnAddFinished(DownloadClient client,
const std::string& guid,
bool success) {
+ stats::LogModelOperationResult(stats::ModelAction::ADD, success);
+
// Don't notify the Client if the entry was already removed.
if (entries_.find(guid) == entries_.end())
return;
@@ -113,6 +121,8 @@ void ModelImpl::OnAddFinished(DownloadClient client,
void ModelImpl::OnUpdateFinished(DownloadClient client,
const std::string& guid,
bool success) {
+ stats::LogModelOperationResult(stats::ModelAction::UPDATE, success);
+
// Don't notify the Client if the entry was already removed.
if (entries_.find(guid) == entries_.end())
return;
@@ -123,6 +133,8 @@ void ModelImpl::OnUpdateFinished(DownloadClient client,
void ModelImpl::OnRemoveFinished(DownloadClient client,
const std::string& guid,
bool success) {
+ stats::LogModelOperationResult(stats::ModelAction::REMOVE, success);
+
DCHECK(entries_.find(guid) == entries_.end());
client_->OnItemRemoved(success, client, guid);
}

Powered by Google App Engine
This is Rietveld 408576698