| 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 "components/dom_distiller/core/distilled_content_store.h" | 5 #include "components/dom_distiller/core/distilled_content_store.h" |
| 6 | 6 |
| 7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 | 8 |
| 9 namespace dom_distiller { | 9 namespace dom_distiller { |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 UrlMap::const_iterator url_it = url_to_id_.find(entry.pages(i).url()); | 42 UrlMap::const_iterator url_it = url_to_id_.find(entry.pages(i).url()); |
| 43 if (url_it != url_to_id_.end()) { | 43 if (url_it != url_to_id_.end()) { |
| 44 it = cache_.Get(url_it->second); | 44 it = cache_.Get(url_it->second); |
| 45 success = it != cache_.end(); | 45 success = it != cache_.end(); |
| 46 if (success) { | 46 if (success) { |
| 47 break; | 47 break; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 scoped_ptr<DistilledArticleProto> distilled_article; | 52 std::unique_ptr<DistilledArticleProto> distilled_article; |
| 53 if (success) { | 53 if (success) { |
| 54 distilled_article.reset(new DistilledArticleProto(*it->second)); | 54 distilled_article.reset(new DistilledArticleProto(*it->second)); |
| 55 } else { | 55 } else { |
| 56 distilled_article.reset(new DistilledArticleProto()); | 56 distilled_article.reset(new DistilledArticleProto()); |
| 57 } | 57 } |
| 58 base::ThreadTaskRunnerHandle::Get()->PostTask( | 58 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 59 FROM_HERE, | 59 FROM_HERE, |
| 60 base::Bind(callback, success, base::Passed(&distilled_article))); | 60 base::Bind(callback, success, base::Passed(&distilled_article))); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void InMemoryContentStore::InjectContent(const ArticleEntry& entry, | 63 void InMemoryContentStore::InjectContent(const ArticleEntry& entry, |
| 64 const DistilledArticleProto& proto) { | 64 const DistilledArticleProto& proto) { |
| 65 cache_.Put(entry.entry_id(), | 65 cache_.Put(entry.entry_id(), |
| 66 scoped_ptr<DistilledArticleProto, CacheDeletor>( | 66 std::unique_ptr<DistilledArticleProto, CacheDeletor>( |
| 67 new DistilledArticleProto(proto), CacheDeletor(this))); | 67 new DistilledArticleProto(proto), CacheDeletor(this))); |
| 68 AddUrlToIdMapping(entry, proto); | 68 AddUrlToIdMapping(entry, proto); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void InMemoryContentStore::AddUrlToIdMapping( | 71 void InMemoryContentStore::AddUrlToIdMapping( |
| 72 const ArticleEntry& entry, | 72 const ArticleEntry& entry, |
| 73 const DistilledArticleProto& proto) { | 73 const DistilledArticleProto& proto) { |
| 74 for (int i = 0; i < proto.pages_size(); i++) { | 74 for (int i = 0; i < proto.pages_size(); i++) { |
| 75 const DistilledPageProto& page = proto.pages(i); | 75 const DistilledPageProto& page = proto.pages(i); |
| 76 if (page.has_url()) { | 76 if (page.has_url()) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 99 void InMemoryContentStore::CacheDeletor::operator()( | 99 void InMemoryContentStore::CacheDeletor::operator()( |
| 100 DistilledArticleProto* proto) { | 100 DistilledArticleProto* proto) { |
| 101 // When InMemoryContentStore is deleted, the |store_| pointer becomes invalid, | 101 // When InMemoryContentStore is deleted, the |store_| pointer becomes invalid, |
| 102 // but since the ContentMap is cleared in the InMemoryContentStore destructor, | 102 // but since the ContentMap is cleared in the InMemoryContentStore destructor, |
| 103 // this should never be called after the destructor. | 103 // this should never be called after the destructor. |
| 104 store_->EraseUrlToIdMapping(*proto); | 104 store_->EraseUrlToIdMapping(*proto); |
| 105 delete proto; | 105 delete proto; |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace dom_distiller | 108 } // namespace dom_distiller |
| OLD | NEW |