OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/pepper/quota_reservation.h" | 5 #include "content/browser/renderer_host/pepper/quota_reservation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file.h" |
10 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webkit/browser/fileapi/quota/quota_reservation.h" | 15 #include "webkit/browser/fileapi/quota/quota_reservation.h" |
15 | 16 |
16 using fileapi::FileSystemType; | 17 using fileapi::FileSystemType; |
17 using fileapi::QuotaReservationManager; | 18 using fileapi::QuotaReservationManager; |
18 | 19 |
19 namespace content { | 20 namespace content { |
(...skipping 15 matching lines...) Expand all Loading... |
35 FakeBackend() {} | 36 FakeBackend() {} |
36 virtual ~FakeBackend() {} | 37 virtual ~FakeBackend() {} |
37 | 38 |
38 virtual void ReserveQuota( | 39 virtual void ReserveQuota( |
39 const GURL& origin, | 40 const GURL& origin, |
40 FileSystemType type, | 41 FileSystemType type, |
41 int64 delta, | 42 int64 delta, |
42 const QuotaReservationManager::ReserveQuotaCallback& callback) OVERRIDE { | 43 const QuotaReservationManager::ReserveQuotaCallback& callback) OVERRIDE { |
43 base::MessageLoopProxy::current()->PostTask( | 44 base::MessageLoopProxy::current()->PostTask( |
44 FROM_HERE, | 45 FROM_HERE, |
45 base::Bind(base::IgnoreResult(callback), base::PLATFORM_FILE_OK)); | 46 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK)); |
46 } | 47 } |
47 | 48 |
48 virtual void ReleaseReservedQuota(const GURL& origin, | 49 virtual void ReleaseReservedQuota(const GURL& origin, |
49 FileSystemType type, | 50 FileSystemType type, |
50 int64 size) OVERRIDE { | 51 int64 size) OVERRIDE { |
51 } | 52 } |
52 | 53 |
53 virtual void CommitQuotaUsage(const GURL& origin, | 54 virtual void CommitQuotaUsage(const GURL& origin, |
54 FileSystemType type, | 55 FileSystemType type, |
55 int64 delta) OVERRIDE { | 56 int64 delta) OVERRIDE { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 scoped_refptr<QuotaReservation> CreateQuotaReservation( | 97 scoped_refptr<QuotaReservation> CreateQuotaReservation( |
97 scoped_refptr<fileapi::QuotaReservation> reservation, | 98 scoped_refptr<fileapi::QuotaReservation> reservation, |
98 const GURL& origin, | 99 const GURL& origin, |
99 FileSystemType type) { | 100 FileSystemType type) { |
100 // Sets reservation_ as a side effect. | 101 // Sets reservation_ as a side effect. |
101 return scoped_refptr<QuotaReservation>( | 102 return scoped_refptr<QuotaReservation>( |
102 new QuotaReservation(reservation, origin, type)); | 103 new QuotaReservation(reservation, origin, type)); |
103 } | 104 } |
104 | 105 |
105 void SetFileSize(const base::FilePath::StringType& file_name, int64 size) { | 106 void SetFileSize(const base::FilePath::StringType& file_name, int64 size) { |
106 bool created = false; | 107 base::File file(MakeFilePath(file_name), |
107 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 108 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); |
108 base::PlatformFile file = CreatePlatformFile( | 109 ASSERT_TRUE(file.IsValid()); |
109 MakeFilePath(file_name), | 110 ASSERT_TRUE(file.SetLength(size)); |
110 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE, | |
111 &created, &error); | |
112 ASSERT_EQ(base::PLATFORM_FILE_OK, error); | |
113 ASSERT_TRUE(base::TruncatePlatformFile(file, size)); | |
114 ASSERT_TRUE(base::ClosePlatformFile(file)); | |
115 } | 111 } |
116 | 112 |
117 QuotaReservationManager* reservation_manager() { | 113 QuotaReservationManager* reservation_manager() { |
118 return reservation_manager_.get(); | 114 return reservation_manager_.get(); |
119 } | 115 } |
120 | 116 |
121 private: | 117 private: |
122 base::MessageLoop message_loop_; | 118 base::MessageLoop message_loop_; |
123 base::ScopedTempDir work_dir_; | 119 base::ScopedTempDir work_dir_; |
124 scoped_ptr<fileapi::QuotaReservationManager> reservation_manager_; | 120 scoped_ptr<fileapi::QuotaReservationManager> reservation_manager_; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 EXPECT_EQ(amount, reserved_quota); | 240 EXPECT_EQ(amount, reserved_quota); |
245 EXPECT_EQ(2U, file_growths.size()); | 241 EXPECT_EQ(2U, file_growths.size()); |
246 EXPECT_EQ(file1_size, file_growths[kFile1ID].max_written_offset); | 242 EXPECT_EQ(file1_size, file_growths[kFile1ID].max_written_offset); |
247 EXPECT_EQ(file3_size, file_growths[kFile3ID].max_written_offset); | 243 EXPECT_EQ(file3_size, file_growths[kFile3ID].max_written_offset); |
248 | 244 |
249 test->CloseFile(kFile1ID, ppapi::FileGrowth(file1_size, 0)); | 245 test->CloseFile(kFile1ID, ppapi::FileGrowth(file1_size, 0)); |
250 test->CloseFile(kFile3ID, ppapi::FileGrowth(file3_size, 0)); | 246 test->CloseFile(kFile3ID, ppapi::FileGrowth(file3_size, 0)); |
251 } | 247 } |
252 | 248 |
253 } // namespace content | 249 } // namespace content |
OLD | NEW |