Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.cc

Issue 10871034: Make all quota-exceeding messages in the storage API explain what the failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make everything a named constant Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/web_request/web_request_api.h" 5 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" 24 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h"
25 #include "chrome/browser/extensions/event_router.h" 25 #include "chrome/browser/extensions/event_router.h"
26 #include "chrome/browser/extensions/extension_info_map.h" 26 #include "chrome/browser/extensions/extension_info_map.h"
27 #include "chrome/browser/extensions/extension_prefs.h" 27 #include "chrome/browser/extensions/extension_prefs.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/extension_tab_id_map.h" 29 #include "chrome/browser/extensions/extension_tab_id_map.h"
30 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/profiles/profile_manager.h" 31 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 32 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
33 #include "chrome/browser/renderer_host/web_cache_manager.h" 33 #include "chrome/browser/renderer_host/web_cache_manager.h"
34 #include "chrome/common/extensions/api/web_request.h"
34 #include "chrome/common/extensions/event_filtering_info.h" 35 #include "chrome/common/extensions/event_filtering_info.h"
35 #include "chrome/common/extensions/extension.h" 36 #include "chrome/common/extensions/extension.h"
36 #include "chrome/common/extensions/extension_constants.h" 37 #include "chrome/common/extensions/extension_constants.h"
37 #include "chrome/common/extensions/extension_error_utils.h" 38 #include "chrome/common/extensions/extension_error_utils.h"
38 #include "chrome/common/extensions/extension_messages.h" 39 #include "chrome/common/extensions/extension_messages.h"
39 #include "chrome/common/extensions/url_pattern.h" 40 #include "chrome/common/extensions/url_pattern.h"
40 #include "chrome/common/url_constants.h" 41 #include "chrome/common/url_constants.h"
41 #include "content/public/browser/browser_message_filter.h" 42 #include "content/public/browser/browser_message_filter.h"
42 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/render_process_host.h" 44 #include "content/public/browser/render_process_host.h"
44 #include "content/public/browser/resource_request_info.h" 45 #include "content/public/browser/resource_request_info.h"
45 #include "googleurl/src/gurl.h" 46 #include "googleurl/src/gurl.h"
46 #include "grit/generated_resources.h" 47 #include "grit/generated_resources.h"
47 #include "net/base/auth.h" 48 #include "net/base/auth.h"
48 #include "net/base/net_errors.h" 49 #include "net/base/net_errors.h"
49 #include "net/http/http_response_headers.h" 50 #include "net/http/http_response_headers.h"
50 #include "net/url_request/url_request.h" 51 #include "net/url_request/url_request.h"
51 #include "ui/base/l10n/l10n_util.h" 52 #include "ui/base/l10n/l10n_util.h"
52 53
53 using content::BrowserMessageFilter; 54 using content::BrowserMessageFilter;
54 using content::BrowserThread; 55 using content::BrowserThread;
55 using content::ResourceRequestInfo; 56 using content::ResourceRequestInfo;
56 using extensions::Extension; 57 using extensions::Extension;
57 58
58 using extensions::web_navigation_api_helpers::GetFrameId; 59 using extensions::web_navigation_api_helpers::GetFrameId;
59 60
60 namespace helpers = extension_web_request_api_helpers; 61 namespace helpers = extension_web_request_api_helpers;
61 namespace keys = extension_web_request_api_constants; 62 namespace keys = extension_web_request_api_constants;
63 namespace web_request = extensions::api::web_request;
62 64
63 namespace { 65 namespace {
64 66
65 // List of all the webRequest events. 67 // List of all the webRequest events.
66 static const char* const kWebRequestEvents[] = { 68 static const char* const kWebRequestEvents[] = {
67 keys::kOnBeforeRedirect, 69 keys::kOnBeforeRedirect,
68 keys::kOnBeforeRequest, 70 keys::kOnBeforeRequest,
69 keys::kOnBeforeSendHeaders, 71 keys::kOnBeforeSendHeaders,
70 keys::kOnCompleted, 72 keys::kOnCompleted,
71 keys::kOnErrorOccurred, 73 keys::kOnErrorOccurred,
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // 1543 //
1542 // As we want to account for the number of times the cache is really cleared 1544 // As we want to account for the number of times the cache is really cleared
1543 // (opposed to the number of times webRequest.handlerBehaviorChanged() is 1545 // (opposed to the number of times webRequest.handlerBehaviorChanged() is
1544 // called), we cannot decide whether a call of 1546 // called), we cannot decide whether a call of
1545 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the 1547 // webRequest.handlerBehaviorChanged() should trigger a quota violation at the
1546 // time it is called. Instead we only decrement the bucket counter at the time 1548 // time it is called. Instead we only decrement the bucket counter at the time
1547 // when the cache is cleared (when page loads happen). 1549 // when the cache is cleared (when page loads happen).
1548 class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic { 1550 class ClearCacheQuotaHeuristic : public QuotaLimitHeuristic {
1549 public: 1551 public:
1550 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map) 1552 ClearCacheQuotaHeuristic(const Config& config, BucketMapper* map)
1551 : QuotaLimitHeuristic(config, map), 1553 : QuotaLimitHeuristic(
1554 config,
1555 map,
1556 "MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES"),
1552 callback_registered_(false), 1557 callback_registered_(false),
1553 weak_ptr_factory_(this) {} 1558 weak_ptr_factory_(this) {}
1554 virtual ~ClearCacheQuotaHeuristic() {} 1559 virtual ~ClearCacheQuotaHeuristic() {}
1555 virtual bool Apply(Bucket* bucket, 1560 virtual bool Apply(Bucket* bucket,
1556 const base::TimeTicks& event_time) OVERRIDE; 1561 const base::TimeTicks& event_time) OVERRIDE;
1557 1562
1558 private: 1563 private:
1559 // Callback that is triggered by the ExtensionWebRequestEventRouter on a page 1564 // Callback that is triggered by the ExtensionWebRequestEventRouter on a page
1560 // load. 1565 // load.
1561 // 1566 //
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( 1780 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled(
1776 profile_id(), extension_id(), event_name, sub_event_name, request_id, 1781 profile_id(), extension_id(), event_name, sub_event_name, request_id,
1777 response.release()); 1782 response.release());
1778 1783
1779 return true; 1784 return true;
1780 } 1785 }
1781 1786
1782 void WebRequestHandlerBehaviorChanged::GetQuotaLimitHeuristics( 1787 void WebRequestHandlerBehaviorChanged::GetQuotaLimitHeuristics(
1783 QuotaLimitHeuristics* heuristics) const { 1788 QuotaLimitHeuristics* heuristics) const {
1784 QuotaLimitHeuristic::Config config = { 1789 QuotaLimitHeuristic::Config config = {
1785 20, // Refill 20 tokens per interval. 1790 // See web_request.json for current value.
1786 base::TimeDelta::FromMinutes(10) // 10 minutes refill interval. 1791 web_request::MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES,
1792 base::TimeDelta::FromMinutes(10)
1787 }; 1793 };
1788 QuotaLimitHeuristic::BucketMapper* bucket_mapper = 1794 QuotaLimitHeuristic::BucketMapper* bucket_mapper =
1789 new QuotaLimitHeuristic::SingletonBucketMapper(); 1795 new QuotaLimitHeuristic::SingletonBucketMapper();
1790 ClearCacheQuotaHeuristic* heuristic = 1796 ClearCacheQuotaHeuristic* heuristic =
1791 new ClearCacheQuotaHeuristic(config, bucket_mapper); 1797 new ClearCacheQuotaHeuristic(config, bucket_mapper);
1792 heuristics->push_back(heuristic); 1798 heuristics->push_back(heuristic);
1793 } 1799 }
1794 1800
1795 void WebRequestHandlerBehaviorChanged::OnQuotaExceeded() { 1801 void WebRequestHandlerBehaviorChanged::OnQuotaExceeded(
1802 const std::string& violation_error) {
1796 // Post warning message. 1803 // Post warning message.
1797 std::set<std::string> extension_ids; 1804 std::set<std::string> extension_ids;
1798 extension_ids.insert(extension_id()); 1805 extension_ids.insert(extension_id());
1799 BrowserThread::PostTask( 1806 BrowserThread::PostTask(
1800 BrowserThread::UI, 1807 BrowserThread::UI,
1801 FROM_HERE, 1808 FROM_HERE,
1802 base::Bind(&ExtensionWarningSet::NotifyWarningsOnUI, 1809 base::Bind(&ExtensionWarningSet::NotifyWarningsOnUI,
1803 profile_id(), 1810 profile_id(),
1804 extension_ids, 1811 extension_ids,
1805 ExtensionWarningSet::kRepeatedCacheFlushes)); 1812 ExtensionWarningSet::kRepeatedCacheFlushes));
(...skipping 26 matching lines...) Expand all
1832 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 1839 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
1833 adblock = true; 1840 adblock = true;
1834 } else { 1841 } else {
1835 other = true; 1842 other = true;
1836 } 1843 }
1837 } 1844 }
1838 } 1845 }
1839 1846
1840 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 1847 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
1841 } 1848 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698