OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/chrome_render_process_observer.h" | 5 #include "chrome/renderer/chrome_render_process_observer.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/memory/weak_ptr.h" |
10 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
11 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
12 #include "base/native_library.h" | 14 #include "base/native_library.h" |
13 #include "base/path_service.h" | 15 #include "base/path_service.h" |
14 #include "base/process_util.h" | 16 #include "base/process_util.h" |
15 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
16 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension_localization_peer.h" | 20 #include "chrome/common/extensions/extension_localization_peer.h" |
19 #include "chrome/common/net/net_resource_provider.h" | 21 #include "chrome/common/net/net_resource_provider.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 using WebKit::WebRuntimeFeatures; | 54 using WebKit::WebRuntimeFeatures; |
53 using content::RenderThread; | 55 using content::RenderThread; |
54 | 56 |
55 namespace { | 57 namespace { |
56 | 58 |
57 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; | 59 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
58 | 60 |
59 class RendererResourceDelegate : public content::ResourceDispatcherDelegate { | 61 class RendererResourceDelegate : public content::ResourceDispatcherDelegate { |
60 public: | 62 public: |
61 RendererResourceDelegate() | 63 RendererResourceDelegate() |
62 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 64 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
63 } | 65 } |
64 | 66 |
65 virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete( | 67 virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete( |
66 webkit_glue::ResourceLoaderBridge::Peer* current_peer, | 68 webkit_glue::ResourceLoaderBridge::Peer* current_peer, |
67 ResourceType::Type resource_type, | 69 ResourceType::Type resource_type, |
68 const net::URLRequestStatus& status) { | 70 const net::URLRequestStatus& status) { |
69 // Update the browser about our cache. | 71 // Update the browser about our cache. |
70 // Rate limit informing the host of our cache stats. | 72 // Rate limit informing the host of our cache stats. |
71 if (method_factory_.empty()) { | 73 if (!weak_factory_.HasWeakPtrs()) { |
72 MessageLoop::current()->PostDelayedTask( | 74 MessageLoop::current()->PostDelayedTask( |
73 FROM_HERE, | 75 FROM_HERE, |
74 method_factory_.NewRunnableMethod( | 76 base::Bind(&RendererResourceDelegate::InformHostOfCacheStats, |
75 &RendererResourceDelegate::InformHostOfCacheStats), | 77 weak_factory_.GetWeakPtr()), |
76 kCacheStatsDelayMS); | 78 kCacheStatsDelayMS); |
77 } | 79 } |
78 | 80 |
79 if (status.status() != net::URLRequestStatus::CANCELED || | 81 if (status.status() != net::URLRequestStatus::CANCELED || |
80 status.error() == net::ERR_ABORTED) { | 82 status.error() == net::ERR_ABORTED) { |
81 return NULL; | 83 return NULL; |
82 } | 84 } |
83 | 85 |
84 // Resource canceled with a specific error are filtered. | 86 // Resource canceled with a specific error are filtered. |
85 return SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( | 87 return SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( |
86 resource_type, current_peer, status.error()); | 88 resource_type, current_peer, status.error()); |
87 } | 89 } |
88 | 90 |
89 virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse( | 91 virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse( |
90 webkit_glue::ResourceLoaderBridge::Peer* current_peer, | 92 webkit_glue::ResourceLoaderBridge::Peer* current_peer, |
91 const std::string& mime_type, | 93 const std::string& mime_type, |
92 const GURL& url) { | 94 const GURL& url) { |
93 return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( | 95 return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( |
94 current_peer, RenderThread::Get(), mime_type, url); | 96 current_peer, RenderThread::Get(), mime_type, url); |
95 } | 97 } |
96 | 98 |
97 private: | 99 private: |
98 void InformHostOfCacheStats() { | 100 void InformHostOfCacheStats() { |
99 WebCache::UsageStats stats; | 101 WebCache::UsageStats stats; |
100 WebCache::getUsageStats(&stats); | 102 WebCache::getUsageStats(&stats); |
101 RenderThread::Get()->Send(new ChromeViewHostMsg_UpdatedCacheStats(stats)); | 103 RenderThread::Get()->Send(new ChromeViewHostMsg_UpdatedCacheStats(stats)); |
102 } | 104 } |
103 | 105 |
104 ScopedRunnableMethodFactory<RendererResourceDelegate> method_factory_; | 106 base::WeakPtrFactory<RendererResourceDelegate> weak_factory_; |
105 | 107 |
106 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate); | 108 DISALLOW_COPY_AND_ASSIGN(RendererResourceDelegate); |
107 }; | 109 }; |
108 | 110 |
109 class RenderViewContentSettingsSetter : public content::RenderViewVisitor { | 111 class RenderViewContentSettingsSetter : public content::RenderViewVisitor { |
110 public: | 112 public: |
111 RenderViewContentSettingsSetter(const GURL& url, | 113 RenderViewContentSettingsSetter(const GURL& url, |
112 const ContentSettings& content_settings) | 114 const ContentSettings& content_settings) |
113 : url_(url), | 115 : url_(url), |
114 content_settings_(content_settings) { | 116 content_settings_(content_settings) { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 429 |
428 const ContentSettingsForOneType* | 430 const ContentSettingsForOneType* |
429 ChromeRenderProcessObserver::image_setting_rules() const { | 431 ChromeRenderProcessObserver::image_setting_rules() const { |
430 return &image_setting_rules_; | 432 return &image_setting_rules_; |
431 } | 433 } |
432 | 434 |
433 const ContentSettings* | 435 const ContentSettings* |
434 ChromeRenderProcessObserver::default_content_settings() const { | 436 ChromeRenderProcessObserver::default_content_settings() const { |
435 return &default_content_settings_; | 437 return &default_content_settings_; |
436 } | 438 } |
OLD | NEW |