Skip to content

Commit

Permalink
Start sorting methods in class declarations.
Browse files Browse the repository at this point in the history
A lot of our headers are a mess and aren't organized. Impose the following
order on files in the base/ directory:

class Blah {
 each public/protected/private section:
  typedefs;
  enums;
  static constants;
  ctors;
  dtors;
  methods;
  overridden virtual methods;
  data members;
};

BUG=68682
TEST=compiles

Review URL: http://codereview.chromium.org/6081007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70749 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
erg@google.com committed Jan 7, 2011
1 parent 8ebb770 commit a502bbe
Show file tree
Hide file tree
Showing 46 changed files with 434 additions and 389 deletions.
16 changes: 8 additions & 8 deletions base/at_exit.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -28,13 +28,6 @@ namespace base {
// callbacks and singleton destructors will be called.

class AtExitManager {
protected:
// This constructor will allow this instance of AtExitManager to be created
// even if one already exists. This should only be used for testing!
// AtExitManagers are kept on a global stack, and it will be removed during
// destruction. This allows you to shadow another AtExitManager.
explicit AtExitManager(bool shadow);

public:
typedef void (*AtExitCallbackType)(void*);

Expand All @@ -52,6 +45,13 @@ class AtExitManager {
// is possible to register new callbacks after calling this function.
static void ProcessCallbacksNow();

protected:
// This constructor will allow this instance of AtExitManager to be created
// even if one already exists. This should only be used for testing!
// AtExitManagers are kept on a global stack, and it will be removed during
// destruction. This allows you to shadow another AtExitManager.
explicit AtExitManager(bool shadow);

private:
struct CallbackAndParam {
CallbackAndParam(AtExitCallbackType func, void* param)
Expand Down
1 change: 1 addition & 0 deletions base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
'path_service.h',
'pickle.cc',
'pickle.h',
'platform_file.cc',
'platform_file.h',
'platform_file_posix.cc',
'platform_file_win.cc',
Expand Down
51 changes: 28 additions & 23 deletions base/command_line.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -29,36 +29,44 @@ class InProcessBrowserTest;

class CommandLine {
public:
#if defined(OS_WIN)
// The type of native command line arguments.
typedef std::wstring StringType;
#elif defined(OS_POSIX)
// The type of native command line arguments.
typedef std::string StringType;
#endif

// The type of map for parsed-out switch key and values.
typedef std::map<std::string, StringType> SwitchMap;

// A constructor for CommandLines that are used only to carry switches and
// arguments.
enum NoProgram { NO_PROGRAM };
explicit CommandLine(NoProgram no_program);

// Construct a new, empty command line.
// |program| is the name of the program to run (aka argv[0]).
explicit CommandLine(const FilePath& program);

#if defined(OS_POSIX)
CommandLine(int argc, const char* const* argv);
explicit CommandLine(const std::vector<std::string>& argv);
#endif

~CommandLine();

#if defined(OS_WIN)
// The type of native command line arguments.
typedef std::wstring StringType;

// Initialize by parsing the given command-line string.
// The program name is assumed to be the first item in the string.
void ParseFromString(const std::wstring& command_line);
static CommandLine FromString(const std::wstring& command_line);
#elif defined(OS_POSIX)
// The type of native command line arguments.
typedef std::string StringType;

// Initialize from an argv vector.
void InitFromArgv(int argc, const char* const* argv);
void InitFromArgv(const std::vector<std::string>& argv);

CommandLine(int argc, const char* const* argv);
explicit CommandLine(const std::vector<std::string>& argv);
#endif

// Construct a new, empty command line.
// |program| is the name of the program to run (aka argv[0]).
explicit CommandLine(const FilePath& program);

// Initialize the current process CommandLine singleton. On Windows,
// ignores its arguments (we instead parse GetCommandLineW()
// directly) because we don't trust the CRT's parsing of the command
Expand Down Expand Up @@ -91,9 +99,6 @@ class CommandLine {
// Get the number of switches in this process.
size_t GetSwitchCount() const { return switches_.size(); }

// The type of map for parsed-out switch key and values.
typedef std::map<std::string, StringType> SwitchMap;

// Get a copy of all switches, along with their values
const SwitchMap& GetSwitches() const {
return switches_;
Expand Down Expand Up @@ -161,6 +166,12 @@ class CommandLine {
// Used by InProcessBrowserTest.
static CommandLine* ForCurrentProcessMutable();

// Returns true and fills in |switch_string| and |switch_value|
// if |parameter_string| represents a switch.
static bool IsSwitch(const StringType& parameter_string,
std::string* switch_string,
StringType* switch_value);

// The singleton CommandLine instance representing the current process's
// command line.
static CommandLine* current_process_commandline_;
Expand All @@ -178,12 +189,6 @@ class CommandLine {
std::vector<std::string> argv_;
#endif

// Returns true and fills in |switch_string| and |switch_value|
// if |parameter_string| represents a switch.
static bool IsSwitch(const StringType& parameter_string,
std::string* switch_string,
StringType* switch_value);

// Parsed-out values.
SwitchMap switches_;

Expand Down
6 changes: 3 additions & 3 deletions base/crypto/rsa_private_key.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -168,6 +168,8 @@ class PrivateKeyInfoCodec {
// TODO(hclam): This class should be ref-counted so it can be reused easily.
class RSAPrivateKey {
public:
~RSAPrivateKey();

// Create a new random instance. Can return NULL if initialization fails.
static RSAPrivateKey* Create(uint16 num_bits);

Expand Down Expand Up @@ -203,8 +205,6 @@ class RSAPrivateKey {
static RSAPrivateKey* FindFromPublicKeyInfo(
const std::vector<uint8>& input);

~RSAPrivateKey();

#if defined(USE_OPENSSL)
EVP_PKEY* key() { return key_; }
#elif defined(USE_NSS)
Expand Down
6 changes: 3 additions & 3 deletions base/crypto/signature_creator.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -33,12 +33,12 @@ namespace base {
// Currently can only sign data using SHA-1 with RSA encryption.
class SignatureCreator {
public:
~SignatureCreator();

// Create an instance. The caller must ensure that the provided PrivateKey
// instance outlives the created SignatureCreator.
static SignatureCreator* Create(RSAPrivateKey* key);

~SignatureCreator();

// Update the signature with more data.
bool Update(const uint8* data_part, int data_part_len);

Expand Down
6 changes: 3 additions & 3 deletions base/file_util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -462,10 +462,10 @@ class FileEnumerator {
WIN32_FIND_DATA find_data_;
HANDLE find_handle_;
#elif defined(OS_POSIX)
typedef struct {
struct DirectoryEntryInfo {
FilePath filename;
struct stat stat;
} DirectoryEntryInfo;
};

// Read the filenames in source into the vector of DirectoryEntryInfo's
static bool ReadDirectory(std::vector<DirectoryEntryInfo>* entries,
Expand Down
33 changes: 17 additions & 16 deletions base/file_util_proxy.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -33,24 +33,34 @@ class FileUtilProxy {
// StatusCallback, in which case the operation will complete silently.
typedef Callback1<PlatformFileError /* error code */>::Type StatusCallback;

typedef Callback3<PlatformFileError /* error code */,
PassPlatformFile,
bool /* created */>::Type CreateOrOpenCallback;
typedef Callback3<PlatformFileError /* error code */,
PassPlatformFile,
FilePath>::Type CreateTemporaryCallback;
typedef Callback2<PlatformFileError /* error code */,
bool /* created */>::Type EnsureFileExistsCallback;
typedef Callback2<PlatformFileError /* error code */,
const PlatformFileInfo& /* file_info */
>::Type GetFileInfoCallback;
typedef Callback2<PlatformFileError /* error code */,
const std::vector<Entry>&>::Type ReadDirectoryCallback;
typedef Callback2<PlatformFileError /* error code */,
int /* bytes read/written */>::Type ReadWriteCallback;

// Creates or opens a file with the given flags. It is invalid to pass NULL
// for the callback.
// If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
// a new file at the given |file_path| and calls back with
// PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists.
typedef Callback3<PlatformFileError /* error code */,
PassPlatformFile,
bool /* created */>::Type CreateOrOpenCallback;
static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
int file_flags,
CreateOrOpenCallback* callback);

// Creates a temporary file for writing. The path and an open file handle
// are returned. It is invalid to pass NULL for the callback.
typedef Callback3<PlatformFileError /* error code */,
PassPlatformFile,
FilePath>::Type CreateTemporaryCallback;
static bool CreateTemporary(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
CreateTemporaryCallback* callback);
Expand All @@ -69,18 +79,13 @@ class FileUtilProxy {
// is set PLATFORM_FILE_OK.
// If the file hasn't existed but it couldn't be created for some other
// reasons, |created| is set false and |error code| indicates the error.
typedef Callback2<PlatformFileError /* error code */,
bool /* created */>::Type EnsureFileExistsCallback;
static bool EnsureFileExists(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
EnsureFileExistsCallback* callback);

// Retrieves the information about a file. It is invalid to pass NULL for the
// callback.
typedef Callback2<PlatformFileError /* error code */,
const PlatformFileInfo& /* file_info */
>::Type GetFileInfoCallback;
static bool GetFileInfo(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
Expand All @@ -91,8 +96,6 @@ class FileUtilProxy {
PlatformFile file,
GetFileInfoCallback* callback);

typedef Callback2<PlatformFileError /* error code */,
const std::vector<Entry>&>::Type ReadDirectoryCallback;
static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
ReadDirectoryCallback* callback);
Expand Down Expand Up @@ -142,8 +145,6 @@ class FileUtilProxy {

// Reads from a file. On success, the file pointer is moved to position
// |offset + bytes_to_read| in the file. The callback can be NULL.
typedef Callback2<PlatformFileError /* error code */,
int /* bytes read/written */>::Type ReadWriteCallback;
static bool Read(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
PlatformFile file,
Expand Down
9 changes: 5 additions & 4 deletions base/global_descriptors_posix.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -37,6 +37,8 @@ namespace base {
class GlobalDescriptors {
public:
typedef uint32_t Key;
typedef std::vector<std::pair<Key, int> > Mapping;

// Often we want a canonical descriptor for a given Key. In this case, we add
// the following constant to the key value:
static const int kBaseDescriptor = 3; // 0, 1, 2 are already taken.
Expand All @@ -46,11 +48,10 @@ class GlobalDescriptors {

// Get a descriptor given a key. It is a fatal error if the key is not known.
int Get(Key key) const;

// Get a descriptor give a key. Returns -1 on error.
int MaybeGet(Key key) const;

typedef std::vector<std::pair<Key, int> > Mapping;

// Set the descriptor for the given key.
void Set(Key key, int fd);

Expand All @@ -59,9 +60,9 @@ class GlobalDescriptors {
}

private:
friend struct DefaultSingletonTraits<GlobalDescriptors>;
GlobalDescriptors();
~GlobalDescriptors();
friend struct DefaultSingletonTraits<GlobalDescriptors>;

Mapping descriptors_;
};
Expand Down
12 changes: 6 additions & 6 deletions base/json/json_reader.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
Expand Down Expand Up @@ -69,18 +69,18 @@ class JSONReader {
Token(Type t, const wchar_t* b, int len)
: type(t), begin(b), length(len) {}

// Get the character that's one past the end of this token.
wchar_t NextChar() {
return *(begin + length);
}

Type type;

// A pointer into JSONReader::json_pos_ that's the beginning of this token.
const wchar_t* begin;

// End should be one char past the end of the token.
int length;

// Get the character that's one past the end of this token.
wchar_t NextChar() {
return *(begin + length);
}
};

// Error codes during parsing.
Expand Down
10 changes: 5 additions & 5 deletions base/logging.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -803,11 +803,11 @@ class Win32ErrorLogMessage {
LogSeverity severity,
SystemErrorCode err);

std::ostream& stream() { return log_message_.stream(); }

// Appends the error message before destructing the encapsulated class.
~Win32ErrorLogMessage();

std::ostream& stream() { return log_message_.stream(); }

private:
SystemErrorCode err_;
// Optional name of the module defining the error.
Expand All @@ -825,11 +825,11 @@ class ErrnoLogMessage {
LogSeverity severity,
SystemErrorCode err);

std::ostream& stream() { return log_message_.stream(); }

// Appends the error message before destructing the encapsulated class.
~ErrnoLogMessage();

std::ostream& stream() { return log_message_.stream(); }

private:
SystemErrorCode err_;
LogMessage log_message_;
Expand Down
Loading

0 comments on commit a502bbe

Please sign in to comment.