| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "config.h" | |
| 6 #include "Cache.h" | |
| 7 #include "base/stats_table.h" | 5 #include "base/stats_table.h" |
| 6 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" |
| 8 #include "webkit/extensions/v8/benchmarking_extension.h" | 7 #include "webkit/extensions/v8/benchmarking_extension.h" |
| 9 #include "webkit/glue/webkit_glue.h" | 8 #include "webkit/glue/webkit_glue.h" |
| 10 | 9 |
| 10 using WebKit::WebCache; |
| 11 |
| 11 namespace extensions_v8 { | 12 namespace extensions_v8 { |
| 12 | 13 |
| 13 const char* kBenchmarkingExtensionName = "v8/Benchmarking"; | 14 const char* kBenchmarkingExtensionName = "v8/Benchmarking"; |
| 14 | 15 |
| 15 class BenchmarkingWrapper : public v8::Extension { | 16 class BenchmarkingWrapper : public v8::Extension { |
| 16 public: | 17 public: |
| 17 BenchmarkingWrapper() : | 18 BenchmarkingWrapper() : |
| 18 v8::Extension(kBenchmarkingExtensionName, | 19 v8::Extension(kBenchmarkingExtensionName, |
| 19 "if (typeof(chrome) == 'undefined') {" | 20 "if (typeof(chrome) == 'undefined') {" |
| 20 " chrome = {};" | 21 " chrome = {};" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 | 51 |
| 51 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { | 52 static v8::Handle<v8::Value> CloseConnections(const v8::Arguments& args) { |
| 52 webkit_glue::CloseCurrentConnections(); | 53 webkit_glue::CloseCurrentConnections(); |
| 53 return v8::Undefined(); | 54 return v8::Undefined(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { | 57 static v8::Handle<v8::Value> ClearCache(const v8::Arguments& args) { |
| 57 // TODO(mbelshe): should be enable/disable? | 58 // TODO(mbelshe): should be enable/disable? |
| 58 webkit_glue::SetCacheMode(false); | 59 webkit_glue::SetCacheMode(false); |
| 59 | 60 |
| 60 // Disabling and re-enabling the cache forces it to flush. | 61 WebCache::clear(); |
| 61 WebCore::cache()->setDisabled(true); | |
| 62 WebCore::cache()->setDisabled(false); | |
| 63 return v8::Undefined(); | 62 return v8::Undefined(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 static v8::Handle<v8::Value> GetCounter(const v8::Arguments& args) { | 65 static v8::Handle<v8::Value> GetCounter(const v8::Arguments& args) { |
| 67 if (!args.Length() || !args[0]->IsString() || !StatsTable::current()) | 66 if (!args.Length() || !args[0]->IsString() || !StatsTable::current()) |
| 68 return v8::Undefined(); | 67 return v8::Undefined(); |
| 69 | 68 |
| 70 // Extract the name argument | 69 // Extract the name argument |
| 71 char name[256]; | 70 char name[256]; |
| 72 name[0] = 'c'; | 71 name[0] = 'c'; |
| 73 name[1] = ':'; | 72 name[1] = ':'; |
| 74 args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3); | 73 args[0]->ToString()->WriteAscii(&name[2], 0, sizeof(name) - 3); |
| 75 | 74 |
| 76 int counter = StatsTable::current()->GetCounterValue(name); | 75 int counter = StatsTable::current()->GetCounterValue(name); |
| 77 return v8::Integer::New(counter); | 76 return v8::Integer::New(counter); |
| 78 } | 77 } |
| 79 }; | 78 }; |
| 80 | 79 |
| 81 v8::Extension* BenchmarkingExtension::Get() { | 80 v8::Extension* BenchmarkingExtension::Get() { |
| 82 return new BenchmarkingWrapper(); | 81 return new BenchmarkingWrapper(); |
| 83 } | 82 } |
| 84 | 83 |
| 85 } // namespace extensions_v8 | 84 } // namespace extensions_v8 |
| OLD | NEW |