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 "chrome/browser/search/instant_io_context.h" | 5 #include "chrome/browser/search/instant_io_context.h" |
6 | 6 |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 #include "content/public/browser/resource_context.h" | 8 #include "content/public/browser/resource_context.h" |
9 #include "content/public/browser/resource_request_info.h" | 9 #include "content/public/browser/resource_request_info.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 if (!info) | 28 if (!info) |
29 return NULL; | 29 return NULL; |
30 | 30 |
31 return GetDataForResourceContext(info->GetContext()); | 31 return GetDataForResourceContext(info->GetContext()); |
32 } | 32 } |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context"; | 36 const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context"; |
37 | 37 |
38 InstantIOContext::InstantIOContext() | 38 InstantIOContext::InstantIOContext() { |
39 : most_visited_item_cache_(kMaxInstantMostVisitedItemCacheSize) { | |
40 // The InstantIOContext is created on the UI thread but is accessed | 39 // The InstantIOContext is created on the UI thread but is accessed |
41 // on the IO thread. | 40 // on the IO thread. |
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
43 } | 42 } |
44 | 43 |
45 InstantIOContext::~InstantIOContext() { | 44 InstantIOContext::~InstantIOContext() { |
46 } | 45 } |
47 | 46 |
48 // static | 47 // static |
49 void InstantIOContext::SetUserDataOnIO( | 48 void InstantIOContext::SetUserDataOnIO( |
(...skipping 20 matching lines...) Expand all Loading... |
70 } | 69 } |
71 | 70 |
72 // static | 71 // static |
73 void InstantIOContext::ClearInstantProcessesOnIO( | 72 void InstantIOContext::ClearInstantProcessesOnIO( |
74 scoped_refptr<InstantIOContext> instant_io_context) { | 73 scoped_refptr<InstantIOContext> instant_io_context) { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
76 instant_io_context->process_ids_.clear(); | 75 instant_io_context->process_ids_.clear(); |
77 } | 76 } |
78 | 77 |
79 // static | 78 // static |
80 void InstantIOContext::AddMostVisitedItemsOnIO( | |
81 scoped_refptr<InstantIOContext> instant_io_context, | |
82 std::vector<InstantMostVisitedItemIDPair> items) { | |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
84 instant_io_context->most_visited_item_cache_.AddItemsWithRestrictedID(items); | |
85 } | |
86 | |
87 | |
88 // static | |
89 bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { | 79 bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { |
90 const content::ResourceRequestInfo* info = | 80 const content::ResourceRequestInfo* info = |
91 content::ResourceRequestInfo::ForRequest(request); | 81 content::ResourceRequestInfo::ForRequest(request); |
92 if (!info) | 82 if (!info) |
93 return false; | 83 return false; |
94 | 84 |
95 InstantIOContext* instant_io_context = GetDataForRequest(request); | 85 InstantIOContext* instant_io_context = GetDataForRequest(request); |
96 if (!instant_io_context) | 86 if (!instant_io_context) |
97 return false; | 87 return false; |
98 | 88 |
99 int process_id = -1; | 89 int process_id = -1; |
100 int render_view_id = -1; | 90 int render_view_id = -1; |
101 if (info->GetAssociatedRenderView(&process_id, &render_view_id) && | 91 if (info->GetAssociatedRenderView(&process_id, &render_view_id) && |
102 instant_io_context->IsInstantProcess(process_id)) | 92 instant_io_context->IsInstantProcess(process_id)) |
103 return true; | 93 return true; |
104 return false; | 94 return false; |
105 } | 95 } |
106 | 96 |
107 // static | |
108 bool InstantIOContext::GetURLForMostVisitedItemID( | |
109 const net::URLRequest* request, | |
110 InstantRestrictedID most_visited_item_id, | |
111 GURL* url) { | |
112 InstantIOContext* instant_io_context = GetDataForRequest(request); | |
113 if (!instant_io_context) { | |
114 *url = GURL(); | |
115 return false; | |
116 } | |
117 | |
118 return instant_io_context->GetURLForMostVisitedItemID(most_visited_item_id, | |
119 url); | |
120 } | |
121 | |
122 bool InstantIOContext::IsInstantProcess(int process_id) const { | 97 bool InstantIOContext::IsInstantProcess(int process_id) const { |
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
124 return process_ids_.find(process_id) != process_ids_.end(); | 99 return process_ids_.find(process_id) != process_ids_.end(); |
125 } | 100 } |
126 | |
127 bool InstantIOContext::GetURLForMostVisitedItemID( | |
128 InstantRestrictedID most_visited_item_id, | |
129 GURL* url) const { | |
130 InstantMostVisitedItem item; | |
131 if (most_visited_item_cache_.GetItemWithRestrictedID(most_visited_item_id, | |
132 &item)) { | |
133 *url = item.url; | |
134 return true; | |
135 } | |
136 | |
137 *url = GURL(); | |
138 return false; | |
139 } | |
OLD | NEW |