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

Side by Side Diff: storage/browser/quota/storage_monitor.cc

Issue 1394563002: Add trace to the caller of QuotaManager::GetAvailableSpace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "storage/browser/quota/storage_monitor.h" 5 #include "storage/browser/quota/storage_monitor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/trace_event/trace_event.h"
10 #include "net/base/net_util.h" 11 #include "net/base/net_util.h"
11 #include "storage/browser/quota/quota_manager.h" 12 #include "storage/browser/quota/quota_manager.h"
12 #include "storage/common/quota/quota_status_code.h" 13 #include "storage/common/quota/quota_status_code.h"
13 14
14 namespace storage { 15 namespace storage {
15 16
16 // StorageObserverList: 17 // StorageObserverList:
17 18
18 StorageObserverList::ObserverState::ObserverState() 19 StorageObserverList::ObserverState::ObserverState()
19 : requires_update(false) { 20 : requires_update(false) {
(...skipping 20 matching lines...) Expand all
40 41
41 void StorageObserverList::OnStorageChange(const StorageObserver::Event& event) { 42 void StorageObserverList::OnStorageChange(const StorageObserver::Event& event) {
42 for (StorageObserverStateMap::iterator it = observers_.begin(); 43 for (StorageObserverStateMap::iterator it = observers_.begin();
43 it != observers_.end(); ++it) { 44 it != observers_.end(); ++it) {
44 it->second.requires_update = true; 45 it->second.requires_update = true;
45 } 46 }
46 47
47 MaybeDispatchEvent(event); 48 MaybeDispatchEvent(event);
48 } 49 }
49 50
50 void StorageObserverList::MaybeDispatchEvent( 51 void StorageObserverList::MaybeDispatchEvent(
michaeln 2015/10/09 00:51:43 and this
oshima 2015/10/09 17:14:09 Done.
51 const StorageObserver::Event& event) { 52 const StorageObserver::Event& event) {
52 notification_timer_.Stop(); 53 notification_timer_.Stop();
53 base::TimeDelta min_delay = base::TimeDelta::Max(); 54 base::TimeDelta min_delay = base::TimeDelta::Max();
54 bool all_observers_notified = true; 55 bool all_observers_notified = true;
55 56
56 for (StorageObserverStateMap::iterator it = observers_.begin(); 57 for (StorageObserverStateMap::iterator it = observers_.begin();
57 it != observers_.end(); ++it) { 58 it != observers_.end(); ++it) {
58 if (!it->second.requires_update) 59 if (!it->second.requires_update)
59 continue; 60 continue;
60 61
61 base::TimeTicks current_time = base::TimeTicks::Now(); 62 base::TimeTicks current_time = base::TimeTicks::Now();
62 base::TimeDelta delta = current_time - it->second.last_notification_time; 63 base::TimeDelta delta = current_time - it->second.last_notification_time;
63 if (it->second.last_notification_time.is_null() || 64 if (it->second.last_notification_time.is_null() ||
64 delta >= it->second.rate) { 65 delta >= it->second.rate) {
65 it->second.requires_update = false; 66 it->second.requires_update = false;
66 it->second.last_notification_time = current_time; 67 it->second.last_notification_time = current_time;
67 68
68 if (it->second.origin == event.filter.origin) { 69 if (it->second.origin == event.filter.origin) {
69 it->first->OnStorageEvent(event); 70 it->first->OnStorageEvent(event);
70 } else { 71 } else {
71 // When the quota and usage of an origin is requested, QuotaManager 72 // When the quota and usage of an origin is requested, QuotaManager
72 // returns the quota and usage of the host. Multiple origins can map to 73 // returns the quota and usage of the host. Multiple origins can map to
73 // to the same host, so ensure the |origin| field in the dispatched 74 // to the same host, so ensure the |origin| field in the dispatched
74 // event matches the |origin| specified by the observer when it was 75 // event matches the |origin| specified by the observer when it was
75 // registered. 76 // registered.
76 StorageObserver::Event dispatch_event(event); 77 StorageObserver::Event dispatch_event(event);
77 dispatch_event.filter.origin = it->second.origin; 78 dispatch_event.filter.origin = it->second.origin;
78 it->first->OnStorageEvent(dispatch_event); 79 it->first->OnStorageEvent(dispatch_event);
michaeln 2015/10/09 00:51:43 and these
79 } 80 }
80 } else { 81 } else {
81 all_observers_notified = false; 82 all_observers_notified = false;
82 base::TimeDelta delay = it->second.rate - delta; 83 base::TimeDelta delay = it->second.rate - delta;
83 if (delay < min_delay) 84 if (delay < min_delay)
84 min_delay = delay; 85 min_delay = delay;
85 } 86 }
86 } 87 }
87 88
88 // We need to respect the notification rate specified by observers. So if it 89 // We need to respect the notification rate specified by observers. So if it
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return; 177 return;
177 } 178 }
178 179
179 StartInitialization(filter); 180 StartInitialization(filter);
180 } 181 }
181 182
182 void HostStorageObservers::StartInitialization( 183 void HostStorageObservers::StartInitialization(
183 const StorageObserver::Filter& filter) { 184 const StorageObserver::Filter& filter) {
184 if (initialized_ || initializing_) 185 if (initialized_ || initializing_)
185 return; 186 return;
187 // crbug.com/349708
188 TRACE_EVENT0("io", "HostStorageObservers::StartInitialization");
186 189
187 initializing_ = true; 190 initializing_ = true;
188 quota_manager_->GetUsageAndQuotaForWebApps( 191 quota_manager_->GetUsageAndQuotaForWebApps(
189 filter.origin, 192 filter.origin,
190 filter.storage_type, 193 filter.storage_type,
191 base::Bind(&HostStorageObservers::GotHostUsageAndQuota, 194 base::Bind(&HostStorageObservers::GotHostUsageAndQuota,
192 weak_factory_.GetWeakPtr(), 195 weak_factory_.GetWeakPtr(),
193 filter)); 196 filter));
194 } 197 }
195 198
196 void HostStorageObservers::GotHostUsageAndQuota( 199 void HostStorageObservers::GotHostUsageAndQuota(
michaeln 2015/10/09 00:51:43 trace this
oshima 2015/10/09 17:14:09 I added trace in OnStorageChange and MaybeDispatch
197 const StorageObserver::Filter& filter, 200 const StorageObserver::Filter& filter,
198 QuotaStatusCode status, 201 QuotaStatusCode status,
199 int64 usage, 202 int64 usage,
200 int64 quota) { 203 int64 quota) {
201 initializing_ = false; 204 initializing_ = false;
202 if (status != kQuotaStatusOk) 205 if (status != kQuotaStatusOk)
203 return; 206 return;
204 207
205 initialized_ = true; 208 initialized_ = true;
206 cached_quota_ = quota; 209 cached_quota_ = quota;
207 cached_usage_ = usage + usage_deltas_during_init_; 210 cached_usage_ = usage + usage_deltas_during_init_;
208 DispatchEvent(filter, event_occurred_before_init_); 211 DispatchEvent(filter, event_occurred_before_init_);
209 } 212 }
210 213
211 void HostStorageObservers::DispatchEvent( 214 void HostStorageObservers::DispatchEvent(
212 const StorageObserver::Filter& filter, bool is_update) { 215 const StorageObserver::Filter& filter, bool is_update) {
213 StorageObserver::Event event(filter, 216 StorageObserver::Event event(filter,
214 std::max<int64>(cached_usage_, 0), 217 std::max<int64>(cached_usage_, 0),
215 std::max<int64>(cached_quota_, 0)); 218 std::max<int64>(cached_quota_, 0));
216 if (is_update) 219 if (is_update)
217 observers_.OnStorageChange(event); 220 observers_.OnStorageChange(event);
michaeln 2015/10/09 00:51:43 and these
oshima 2015/10/09 17:14:09 ditto
218 else 221 else
219 observers_.MaybeDispatchEvent(event); 222 observers_.MaybeDispatchEvent(event);
220 } 223 }
221 224
222 225
223 // StorageTypeObservers: 226 // StorageTypeObservers:
224 227
225 StorageTypeObservers::StorageTypeObservers(QuotaManager* quota_manager) 228 StorageTypeObservers::StorageTypeObservers(QuotaManager* quota_manager)
226 : quota_manager_(quota_manager) { 229 : quota_manager_(quota_manager) {
227 } 230 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 373
371 StorageTypeObserversMap::iterator it = 374 StorageTypeObserversMap::iterator it =
372 storage_type_observers_map_.find(filter.storage_type); 375 storage_type_observers_map_.find(filter.storage_type);
373 if (it == storage_type_observers_map_.end()) 376 if (it == storage_type_observers_map_.end())
374 return; 377 return;
375 378
376 it->second->NotifyUsageChange(filter, delta); 379 it->second->NotifyUsageChange(filter, delta);
377 } 380 }
378 381
379 } // namespace storage 382 } // namespace storage
OLDNEW
« storage/browser/quota/quota_manager.cc ('K') | « storage/browser/quota/quota_manager_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698