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

Side by Side Diff: webkit/quota/mock_quota_manager.cc

Issue 7129018: Time-based removal of temporary file systems via BrowsingDataRemover (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const_iterator. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/quota/mock_quota_manager.h"
6
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "googleurl/src/gurl.h"
14 #include "webkit/quota/quota_client.h"
15 #include "webkit/quota/quota_manager.h"
16 #include "webkit/quota/quota_task.h"
17 #include "webkit/quota/quota_types.h"
18
19 // Done so that we can use PostTask on MockQuotaManager and not have
20 // MockQuotaManager implement RefCounted.
jochen (gone - plz use gerrit) 2011/07/26 08:55:33 but isn't the base class, quota manager already re
Mike West 2011/07/26 12:08:32 You're right. I don't know why I thought I needed
21 DISABLE_RUNNABLE_METHOD_REFCOUNT(quota::MockQuotaManager);
22
23 namespace quota {
24
25 class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
26 public:
27 GetModifiedSinceTask(MockQuotaManager* manager,
28 const std::set<GURL>& origins, GetOriginsCallback* callback)
jochen (gone - plz use gerrit) 2011/07/26 08:55:33 all arguments on their own line, and aligned
Mike West 2011/07/26 12:08:32 Done.
29 : QuotaThreadTask(manager, manager->io_thread_),
30 origins_(origins),
31 callback_(callback) {}
32
33 protected:
34 virtual void RunOnTargetThread() OVERRIDE {}
35
36 virtual void Completed() OVERRIDE {
37 callback_->Run(origins_);
38 }
39
40 virtual void Aborted() OVERRIDE {
41 callback_->Run(std::set<GURL>());
42 }
43
44 private:
45 std::set<GURL> origins_;
46 scoped_ptr<GetOriginsCallback> callback_;
47 };
jochen (gone - plz use gerrit) 2011/07/26 08:55:33 disallow copy/assign
Mike West 2011/07/26 12:08:32 Done.
48
49 class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask {
50 public:
51 DeleteOriginDataTask(MockQuotaManager* manager,
52 StatusCallback* callback)
53 : QuotaThreadTask(manager, manager->io_thread_),
54 callback_(callback) {}
55
56 protected:
57 virtual void RunOnTargetThread() OVERRIDE {}
58
59 virtual void Completed() OVERRIDE {
60 callback_->Run(quota::kQuotaStatusOk);
61 }
62
63 virtual void Aborted() OVERRIDE {
64 callback_->Run(quota::kQuotaErrorAbort);
65 }
66
67 private:
68 scoped_ptr<StatusCallback> callback_;
69 };
70
71 MockQuotaManager::OriginInfo::OriginInfo(
72 const GURL& origin,
73 StorageType type,
74 base::Time modified)
75 : origin(origin),
76 type(type),
77 modified(modified) {
78 }
79
80 MockQuotaManager::OriginInfo::~OriginInfo() {}
81
82 MockQuotaManager::MockQuotaManager(bool is_incognito,
83 const FilePath& profile_path, base::MessageLoopProxy* io_thread,
84 base::MessageLoopProxy* db_thread,
85 SpecialStoragePolicy* special_storage_policy)
86 : QuotaManager(is_incognito, profile_path, io_thread, db_thread,
87 special_storage_policy) {
88 }
89
90 MockQuotaManager::~MockQuotaManager() {}
91
92 bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type,
93 base::Time modified) {
94 origins_.push_back(OriginInfo(origin, type, modified));
95 return true;
96 }
97
98 bool MockQuotaManager::OriginHasData(const GURL& origin,
99 StorageType type) {
100 for (std::vector<OriginInfo>::iterator current = origins_.begin();
101 current != origins_.end();
102 ++current) {
103 if (current->origin == origin && current->type == type)
104 return true;
105 }
106 return false;
107 }
108
109 void MockQuotaManager::GetOriginsModifiedSince(StorageType type,
110 base::Time modified_since, GetOriginsCallback* callback) {
111 std::set<GURL> origins_to_return;
112 for (std::vector<OriginInfo>::iterator current = origins_.begin();
113 current != origins_.end();
114 ++current) {
115 if (current->type == type && current->modified >= modified_since)
116 origins_to_return.insert(current->origin);
117 }
118 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return,
119 callback))->Start();
120 }
121
122 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type,
123 StatusCallback* callback) {
124 for (std::vector<OriginInfo>::iterator current = origins_.begin();
125 current != origins_.end();
126 ++current) {
127 if (current->origin == origin && current->type == type) {
128 origins_.erase(current);
129 break;
130 }
131 }
132 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start();
133 }
134
135 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698