| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chromeos/printing/ppd_cache.h" | 5 #include "chromeos/printing/ppd_cache.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 static_cast<int>(checksum.size())) { | 109 static_cast<int>(checksum.size())) { |
| 110 LOG(ERROR) << "Failed to create ppd cache file"; | 110 LOG(ERROR) << "Failed to create ppd cache file"; |
| 111 file.Close(); | 111 file.Close(); |
| 112 if (!base::DeleteFile(path, false)) { | 112 if (!base::DeleteFile(path, false)) { |
| 113 LOG(ERROR) << "Failed to cleanup failed creation."; | 113 LOG(ERROR) << "Failed to cleanup failed creation."; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Implementation of the PpdCache that uses two separate task runners for Store |
| 120 // and Fetch since the two operations have different priorities. Note that the |
| 121 // two operations are not sequenced so there should be no expectation that a |
| 122 // call to Find will return a file that was previously Stored until the Store |
| 123 // callback is run. |
| 119 class PpdCacheImpl : public PpdCache { | 124 class PpdCacheImpl : public PpdCache { |
| 120 public: | 125 public: |
| 121 explicit PpdCacheImpl(const base::FilePath& cache_base_dir) | 126 explicit PpdCacheImpl(const base::FilePath& cache_base_dir) |
| 122 : cache_base_dir_(cache_base_dir), | 127 : cache_base_dir_(cache_base_dir), |
| 123 fetch_task_runner_(base::CreateSequencedTaskRunnerWithTraits( | 128 fetch_task_runner_(base::CreateSequencedTaskRunnerWithTraits( |
| 124 {base::TaskPriority::USER_VISIBLE, base::MayBlock(), | 129 {base::TaskPriority::USER_VISIBLE, base::MayBlock(), |
| 125 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), | 130 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), |
| 126 store_task_runner_(base::CreateSequencedTaskRunnerWithTraits( | 131 store_task_runner_(base::CreateSequencedTaskRunnerWithTraits( |
| 127 {base::TaskPriority::BACKGROUND, base::MayBlock(), | 132 {base::TaskPriority::BACKGROUND, base::MayBlock(), |
| 128 base::TaskShutdownBehavior::BLOCK_SHUTDOWN})) {} | 133 base::TaskShutdownBehavior::BLOCK_SHUTDOWN})) {} |
| (...skipping 26 matching lines...) Expand all Loading... |
| 155 | 160 |
| 156 } // namespace | 161 } // namespace |
| 157 | 162 |
| 158 // static | 163 // static |
| 159 scoped_refptr<PpdCache> PpdCache::Create(const base::FilePath& cache_base_dir) { | 164 scoped_refptr<PpdCache> PpdCache::Create(const base::FilePath& cache_base_dir) { |
| 160 return scoped_refptr<PpdCache>(new PpdCacheImpl(cache_base_dir)); | 165 return scoped_refptr<PpdCache>(new PpdCacheImpl(cache_base_dir)); |
| 161 } | 166 } |
| 162 | 167 |
| 163 } // namespace printing | 168 } // namespace printing |
| 164 } // namespace chromeos | 169 } // namespace chromeos |
| OLD | NEW |