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

Side by Side Diff: chrome/test/automation/javascript_execution_controller.h

Issue 10383262: RefCounted types should not have public destructors, delegate cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make win bot happy Created 8 years, 5 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) 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 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ 5 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_
6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/test/automation/javascript_message_utils.h" 15 #include "chrome/test/automation/javascript_message_utils.h"
16 16
17 class JavaScriptObjectProxy; 17 class JavaScriptObjectProxy;
18 18
19 // This class handles the execution of arbitrary JavaScript, preparing it for 19 // This class handles the execution of arbitrary JavaScript, preparing it for
20 // execution, and parsing its result (in JSON). It keeps track of all returned 20 // execution, and parsing its result (in JSON). It keeps track of all returned
21 // JavaScript objects. 21 // JavaScript objects.
22 class JavaScriptExecutionController 22 class JavaScriptExecutionController
23 : public base::SupportsWeakPtr<JavaScriptExecutionController> { 23 : public base::SupportsWeakPtr<JavaScriptExecutionController> {
24 public: 24 public:
25 JavaScriptExecutionController(); 25 JavaScriptExecutionController();
26 virtual ~JavaScriptExecutionController();
27 26
28 // Executes |script| and parse the return value. Returns whether the 27 // Executes |script| and parse the return value. Returns whether the
29 // execution and parsing succeeded. 28 // execution and parsing succeeded.
30 template <typename T> 29 template <typename T>
31 bool ExecuteJavaScriptAndGetReturn(const std::string& script, T* result) { 30 bool ExecuteJavaScriptAndGetReturn(const std::string& script, T* result) {
32 scoped_ptr<Value> returnValue; 31 scoped_ptr<Value> returnValue;
33 if (!ExecuteAndParseHelper(WrapJavaScript(script), &returnValue)) 32 if (!ExecuteAndParseHelper(WrapJavaScript(script), &returnValue))
34 return false; 33 return false;
35 return ValueConversionTraits<T>::SetFromValue(returnValue.get(), result); 34 return ValueConversionTraits<T>::SetFromValue(returnValue.get(), result);
36 } 35 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 obj = static_cast<JavaScriptObject*>(iter->second); 68 obj = static_cast<JavaScriptObject*>(iter->second);
70 } 69 }
71 return obj; 70 return obj;
72 } 71 }
73 72
74 // Sets a timeout to be used for all JavaScript methods in which a response 73 // Sets a timeout to be used for all JavaScript methods in which a response
75 // is returned asynchronously. 74 // is returned asynchronously.
76 static void set_timeout(int timeout_ms) { timeout_ms_ = timeout_ms; } 75 static void set_timeout(int timeout_ms) { timeout_ms_ = timeout_ms; }
77 76
78 protected: 77 protected:
78 virtual ~JavaScriptExecutionController();
79
79 // Executes |script| and sets the JSON response |json|. Returns true 80 // Executes |script| and sets the JSON response |json|. Returns true
80 // on success. 81 // on success.
81 virtual bool ExecuteJavaScriptAndGetJSON(const std::string& script, 82 virtual bool ExecuteJavaScriptAndGetJSON(const std::string& script,
82 std::string* json) = 0; 83 std::string* json) = 0;
83 84
84 // Called when this controller is tracking its first object. Used by 85 // Called when this controller is tracking its first object. Used by
85 // reference counted subclasses. 86 // reference counted subclasses.
86 virtual void FirstObjectAdded() {} 87 virtual void FirstObjectAdded() {}
87 88
88 // Called when this controller is no longer tracking any objects. Used by 89 // Called when this controller is no longer tracking any objects. Used by
(...skipping 24 matching lines...) Expand all
113 // Timeout to use for all asynchronous methods. 114 // Timeout to use for all asynchronous methods.
114 static int timeout_ms_; 115 static int timeout_ms_;
115 116
116 // Weak pointer to all the object proxies that we create. 117 // Weak pointer to all the object proxies that we create.
117 HandleToObjectMap handle_to_object_; 118 HandleToObjectMap handle_to_object_;
118 119
119 DISALLOW_COPY_AND_ASSIGN(JavaScriptExecutionController); 120 DISALLOW_COPY_AND_ASSIGN(JavaScriptExecutionController);
120 }; 121 };
121 122
122 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_ 123 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_EXECUTION_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/print_system.h ('k') | chrome/test/automation/javascript_execution_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698