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

Side by Side Diff: components/offline_items_collection/core/offline_content_aggregator.cc

Issue 2833793002: Added AddDownload communication path and observers
Patch Set: Created 3 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 24 matching lines...) Expand all
35 35
36 void OfflineContentAggregator::RegisterProvider( 36 void OfflineContentAggregator::RegisterProvider(
37 const std::string& name_space, 37 const std::string& name_space,
38 OfflineContentProvider* provider) { 38 OfflineContentProvider* provider) {
39 // Validate that this is the first OfflineContentProvider registered that is 39 // Validate that this is the first OfflineContentProvider registered that is
40 // associated with |name_space|. 40 // associated with |name_space|.
41 DCHECK(providers_.find(name_space) == providers_.end()); 41 DCHECK(providers_.find(name_space) == providers_.end());
42 42
43 // Only set up the connection to the provider if the provider isn't associated 43 // Only set up the connection to the provider if the provider isn't associated
44 // with any other namespace. 44 // with any other namespace.
45 bool need_add_observer = false;
harkness 2017/04/20 12:25:16 dtrainor: This is ugly, but I threw it in there to
Peter Beverloo 2017/04/20 16:27:55 There's a race condition there. If the OCA would s
David Trainor- moved to gerrit 2017/04/25 03:24:42 It actually does queue them up and flush them once
45 if (!MapContainsValue(providers_, provider)) 46 if (!MapContainsValue(providers_, provider))
46 provider->AddObserver(this); 47 need_add_observer = true;
47 48
48 providers_[name_space] = provider; 49 providers_[name_space] = provider;
50
51 if (need_add_observer)
52 provider->AddObserver(this);
49 } 53 }
50 54
51 void OfflineContentAggregator::UnregisterProvider( 55 void OfflineContentAggregator::UnregisterProvider(
52 const std::string& name_space) { 56 const std::string& name_space) {
53 auto provider_it = providers_.find(name_space); 57 auto provider_it = providers_.find(name_space);
54 58
55 OfflineContentProvider* provider = provider_it->second; 59 OfflineContentProvider* provider = provider_it->second;
56 providers_.erase(provider_it); 60 providers_.erase(provider_it);
57 61
58 // Only clean up the connection to the provider if the provider isn't 62 // Only clean up the connection to the provider if the provider isn't
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 272
269 void OfflineContentAggregator::RunIfReady(OfflineContentProvider* provider, 273 void OfflineContentAggregator::RunIfReady(OfflineContentProvider* provider,
270 const base::Closure& action) { 274 const base::Closure& action) {
271 if (provider->AreItemsAvailable()) 275 if (provider->AreItemsAvailable())
272 action.Run(); 276 action.Run();
273 else 277 else
274 pending_actions_[provider].push_back(action); 278 pending_actions_[provider].push_back(action);
275 } 279 }
276 280
277 } // namespace offline_items_collection 281 } // namespace offline_items_collection
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698