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

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: Rebase. 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
« no previous file with comments | « webkit/quota/mock_quota_manager.h ('k') | webkit/quota/mock_quota_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace quota {
20
21 class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask {
22 public:
23 GetModifiedSinceTask(MockQuotaManager* manager,
24 const std::set<GURL>& origins,
25 GetOriginsCallback* callback)
26 : QuotaThreadTask(manager, manager->io_thread_),
27 origins_(origins),
28 callback_(callback) {}
29
30 protected:
31 virtual void RunOnTargetThread() OVERRIDE {}
32
33 virtual void Completed() OVERRIDE {
34 callback_->Run(origins_);
35 }
36
37 virtual void Aborted() OVERRIDE {
38 callback_->Run(std::set<GURL>());
39 }
40
41 private:
42 std::set<GURL> origins_;
43 scoped_ptr<GetOriginsCallback> callback_;
44
45 DISALLOW_COPY_AND_ASSIGN(GetModifiedSinceTask);
46 };
47
48 class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask {
49 public:
50 DeleteOriginDataTask(MockQuotaManager* manager,
51 StatusCallback* callback)
52 : QuotaThreadTask(manager, manager->io_thread_),
53 callback_(callback) {}
54
55 protected:
56 virtual void RunOnTargetThread() OVERRIDE {}
57
58 virtual void Completed() OVERRIDE {
59 callback_->Run(quota::kQuotaStatusOk);
60 }
61
62 virtual void Aborted() OVERRIDE {
63 callback_->Run(quota::kQuotaErrorAbort);
64 }
65
66 private:
67 scoped_ptr<StatusCallback> callback_;
68
69 DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask);
70 };
71
72 MockQuotaManager::OriginInfo::OriginInfo(
73 const GURL& origin,
74 StorageType type,
75 base::Time modified)
76 : origin(origin),
77 type(type),
78 modified(modified) {
79 }
80
81 MockQuotaManager::OriginInfo::~OriginInfo() {}
82
83 MockQuotaManager::MockQuotaManager(bool is_incognito,
84 const FilePath& profile_path, base::MessageLoopProxy* io_thread,
85 base::MessageLoopProxy* db_thread,
86 SpecialStoragePolicy* special_storage_policy)
87 : QuotaManager(is_incognito, profile_path, io_thread, db_thread,
88 special_storage_policy) {
89 }
90
91 MockQuotaManager::~MockQuotaManager() {}
92
93 bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type,
94 base::Time modified) {
95 origins_.push_back(OriginInfo(origin, type, modified));
96 return true;
97 }
98
99 bool MockQuotaManager::OriginHasData(const GURL& origin,
100 StorageType type) const {
101 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
102 current != origins_.end();
103 ++current) {
104 if (current->origin == origin && current->type == type)
105 return true;
106 }
107 return false;
108 }
109
110 void MockQuotaManager::GetOriginsModifiedSince(StorageType type,
111 base::Time modified_since, GetOriginsCallback* callback) {
112 std::set<GURL> origins_to_return;
113 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
114 current != origins_.end();
115 ++current) {
116 if (current->type == type && current->modified >= modified_since)
117 origins_to_return.insert(current->origin);
118 }
119 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return,
120 callback))->Start();
121 }
122
123 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type,
124 StatusCallback* callback) {
125 for (std::vector<OriginInfo>::iterator current = origins_.begin();
126 current != origins_.end();
127 ++current) {
128 if (current->origin == origin && current->type == type) {
129 origins_.erase(current);
130 break;
131 }
132 }
133 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start();
134 }
135
136 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/quota/mock_quota_manager.h ('k') | webkit/quota/mock_quota_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698