Index: chrome/browser/instant/instant_io_context.cc |
diff --git a/chrome/browser/instant/instant_io_context.cc b/chrome/browser/instant/instant_io_context.cc |
index a4ab4fd6e342bdfa11700553b1c08e5bf4619fc6..3e6560525ca8d117ca6058b2f2a4c01b728c7e61 100644 |
--- a/chrome/browser/instant/instant_io_context.cc |
+++ b/chrome/browser/instant/instant_io_context.cc |
@@ -7,84 +7,73 @@ |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/resource_context.h" |
#include "content/public/browser/resource_request_info.h" |
-#include "net/url_request/url_request.h" |
- |
-using content::BrowserThread; |
namespace { |
-// Retrieves the Instant data from the |context|'s named user-data. |
-InstantIOContext* GetDataForResourceContext( |
- content::ResourceContext* context) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- return base::UserDataAdapter<InstantIOContext>::Get( |
- context, InstantIOContext::kInstantIOContextKeyName); |
-} |
+char kUserDataKey; |
} // namespace |
-const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context"; |
- |
InstantIOContext::InstantIOContext() { |
- // The InstantIOContext is created on the UI thread but is accessed |
- // on the IO thread. |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
-} |
- |
-InstantIOContext::~InstantIOContext() { |
+ // This object is created on the UI thread but accessed on the IO thread. |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
} |
// static |
void InstantIOContext::SetUserDataOnIO( |
content::ResourceContext* resource_context, |
- scoped_refptr<InstantIOContext> instant_io_context) { |
+ scoped_refptr<InstantIOContext> io_context) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
resource_context->SetUserData( |
- InstantIOContext::kInstantIOContextKeyName, |
- new base::UserDataAdapter<InstantIOContext>(instant_io_context)); |
+ &kUserDataKey, |
+ new base::UserDataAdapter<InstantIOContext>(io_context)); |
} |
// static |
void InstantIOContext::AddInstantProcessOnIO( |
- scoped_refptr<InstantIOContext> instant_io_context, int process_id) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- instant_io_context->process_ids_.insert(process_id); |
+ scoped_refptr<InstantIOContext> io_context, |
+ int process_id) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ io_context->process_ids_.insert(process_id); |
} |
// static |
void InstantIOContext::RemoveInstantProcessOnIO( |
- scoped_refptr<InstantIOContext> instant_io_context, int process_id) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- instant_io_context->process_ids_.erase(process_id); |
-} |
- |
-// static |
-void InstantIOContext::ClearInstantProcessesOnIO( |
- scoped_refptr<InstantIOContext> instant_io_context) { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- instant_io_context->process_ids_.clear(); |
+ scoped_refptr<InstantIOContext> io_context, |
+ int process_id) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ io_context->process_ids_.erase(process_id); |
} |
// static |
bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ |
const content::ResourceRequestInfo* info = |
content::ResourceRequestInfo::ForRequest(request); |
if (!info) |
return false; |
- InstantIOContext* instant_io_context = |
- GetDataForResourceContext(info->GetContext()); |
- if (!instant_io_context) |
+ InstantIOContext* io_context = |
+ base::UserDataAdapter<InstantIOContext>::Get(info->GetContext(), |
+ &kUserDataKey); |
+ if (!io_context) |
return false; |
int process_id = -1; |
int render_view_id = -1; |
if (info->GetAssociatedRenderView(&process_id, &render_view_id) && |
- instant_io_context->IsInstantProcess(process_id)) |
+ io_context->IsInstantProcess(process_id)) |
return true; |
+ |
return false; |
} |
+InstantIOContext::~InstantIOContext() { |
+ // Destruction could happen on either thread (UI or IO). |
+} |
+ |
bool InstantIOContext::IsInstantProcess(int process_id) const { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- return process_ids_.count(process_id) != 0; |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ return process_ids_.find(process_id) != process_ids_.end(); |
} |