Home | History | Annotate | Download | only in sync
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SYNC_JS_ARG_LIST_H_
      6 #define CHROME_BROWSER_SYNC_JS_ARG_LIST_H_
      7 #pragma once
      8 
      9 // See README.js for design comments.
     10 
     11 #include <string>
     12 #include <vector>
     13 
     14 #include "base/memory/ref_counted.h"
     15 #include "base/values.h"
     16 
     17 namespace browser_sync {
     18 
     19 // A thread-safe ref-counted wrapper around an immutable ListValue.
     20 // Used for passing around argument lists to different threads.
     21 class JsArgList {
     22  public:
     23   JsArgList();
     24   explicit JsArgList(const ListValue& args);
     25   explicit JsArgList(const std::vector<const Value*>& args);
     26   ~JsArgList();
     27 
     28   const ListValue& Get() const;
     29 
     30   std::string ToString() const;
     31 
     32  private:
     33   class SharedListValue : public base::RefCountedThreadSafe<SharedListValue> {
     34    public:
     35     SharedListValue();
     36     explicit SharedListValue(const ListValue& list_value);
     37     explicit SharedListValue(const std::vector<const Value*>& value_list);
     38 
     39     const ListValue& Get() const;
     40 
     41    private:
     42     virtual ~SharedListValue();
     43     friend class base::RefCountedThreadSafe<SharedListValue>;
     44 
     45     ListValue list_value_;
     46   };
     47 
     48   scoped_refptr<const SharedListValue> args_;
     49 
     50   // Copy constructor and assignment operator welcome.
     51 };
     52 
     53 }  // namespace browser_sync
     54 
     55 #endif  // CHROME_BROWSER_SYNC_JS_ARG_LIST_H_
     56