| OLD | NEW |
| 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 "chrome/browser/extensions/updater/local_extension_cache.h" | 5 #include "chrome/browser/extensions/updater/local_extension_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 const base::Time& timestamp, | 98 const base::Time& timestamp, |
| 99 base::FilePath* filename) { | 99 base::FilePath* filename) { |
| 100 std::string data(size, 0); | 100 std::string data(size, 0); |
| 101 | 101 |
| 102 crypto::SecureHash* hash = | 102 crypto::SecureHash* hash = |
| 103 crypto::SecureHash::Create(crypto::SecureHash::SHA256); | 103 crypto::SecureHash::Create(crypto::SecureHash::SHA256); |
| 104 hash->Update(data.c_str(), size); | 104 hash->Update(data.c_str(), size); |
| 105 uint8 output[crypto::kSHA256Length]; | 105 uint8 output[crypto::kSHA256Length]; |
| 106 hash->Finish(output, sizeof(output)); | 106 hash->Finish(output, sizeof(output)); |
| 107 const std::string hex_hash = | 107 const std::string hex_hash = |
| 108 base::StringToLowerASCII(base::HexEncode(output, sizeof(output))); | 108 base::ToLowerASCII(base::HexEncode(output, sizeof(output))); |
| 109 delete hash; | 109 delete hash; |
| 110 | 110 |
| 111 const base::FilePath file = | 111 const base::FilePath file = |
| 112 GetExtensionFileName(dir, id, version, hex_hash); | 112 GetExtensionFileName(dir, id, version, hex_hash); |
| 113 if (filename) | 113 if (filename) |
| 114 *filename = file; | 114 *filename = file; |
| 115 EXPECT_EQ(base::WriteFile(file, data.data(), data.size()), int(size)); | 115 EXPECT_EQ(base::WriteFile(file, data.data(), data.size()), int(size)); |
| 116 EXPECT_TRUE(base::TouchFile(file, timestamp, timestamp)); | 116 EXPECT_TRUE(base::TouchFile(file, timestamp, timestamp)); |
| 117 | 117 |
| 118 return hex_hash; | 118 return hex_hash; |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 const base::FilePath hashed2 = | 481 const base::FilePath hashed2 = |
| 482 GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); | 482 GetExtensionFileName(cache_dir, kTestExtensionId1, "3.0", hash4); |
| 483 EXPECT_TRUE(base::PathExists(hashed2)); | 483 EXPECT_TRUE(base::PathExists(hashed2)); |
| 484 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); | 484 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash4, NULL, NULL)); |
| 485 // Old file kept | 485 // Old file kept |
| 486 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); | 486 EXPECT_TRUE(cache.GetExtension(kTestExtensionId1, hash3, NULL, NULL)); |
| 487 EXPECT_TRUE(base::DeleteFile(temp7, false)); | 487 EXPECT_TRUE(base::DeleteFile(temp7, false)); |
| 488 } | 488 } |
| 489 | 489 |
| 490 } // namespace extensions | 490 } // namespace extensions |
| OLD | NEW |