| Index: chrome/browser/net/net_log_temp_file.h
 | 
| ===================================================================
 | 
| --- chrome/browser/net/net_log_temp_file.h	(revision 0)
 | 
| +++ chrome/browser/net/net_log_temp_file.h	(revision 0)
 | 
| @@ -0,0 +1,96 @@
 | 
| +// Copyright (c) 2013 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.
 | 
| +
 | 
| +#ifndef CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_
 | 
| +#define CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_
 | 
| +
 | 
| +#include <string>
 | 
| +
 | 
| +#include "base/basictypes.h"
 | 
| +#include "base/file_path.h"
 | 
| +#include "base/memory/scoped_ptr.h"
 | 
| +#include "base/synchronization/lock.h"
 | 
| +
 | 
| +namespace base {
 | 
| +class Value;
 | 
| +}
 | 
| +
 | 
| +class NetLogLogger;
 | 
| +
 | 
| +// NetLogTempFile logs all the net_log entries into a temporary file created in
 | 
| +// "NetLogs" folder in file_util::GetTempDir() directory.
 | 
| +//
 | 
| +// NetLogTempFile maintains the current state (state_) of the logging into a
 | 
| +// temporary file.
 | 
| +//
 | 
| +// The following are the possible states
 | 
| +// a) Only Start is allowed (state_ == UNINITIALIZED).
 | 
| +// b) Only Stop is allowed (state_ == ALLOW_STOP).
 | 
| +// c) Either Send or Start is allowed (state_ == ALLOW_START_SEND).
 | 
| +class NetLogTempFile {
 | 
| + public:
 | 
| +  // This enum lists the UI button commands it could receive.
 | 
| +  enum Command {
 | 
| +    DO_START,          // Call StartLog.
 | 
| +    DO_STOP,           // Call StopLog.
 | 
| +    DO_SEND,           // Call SendLog.
 | 
| +  };
 | 
| +
 | 
| +  // This enum lists the possible state NetLogTempFile could be in.
 | 
| +  enum State {
 | 
| +    UNINITIALIZED,
 | 
| +    ALLOW_START,          // Only StartLog is allowed.
 | 
| +    ALLOW_STOP,           // Only StopLog is allowed.
 | 
| +    ALLOW_START_SEND,     // Either OnSendLog or OnStartLog calls are allowed.
 | 
| +  };
 | 
| +
 | 
| +  // Constructs a NetLogTempFile. Only one instance is created in
 | 
| +  // browser process.
 | 
| +  NetLogTempFile();
 | 
| +  ~NetLogTempFile();
 | 
| +
 | 
| +  // Accepts the button command and executes them.
 | 
| +  void ProcessCommand(Command command);
 | 
| +
 | 
| +  // Creates a Value summary of the state of the NetLogTempFile. The caller is
 | 
| +  // responsible for deleting the returned value.
 | 
| +  base::Value* NetLogTempFileToValue();
 | 
| +
 | 
| + private:
 | 
| +  // Initializes the |state_| to either ALLOW_START (if there is no temporary
 | 
| +  // file from earlier run) or ALLOW_START_SEND (if there is a temporary file
 | 
| +  // from earlier run).
 | 
| +  void Init();
 | 
| +
 | 
| +  // Start collecting NetLog data into a temporary file in "NetLogs" folder in
 | 
| +  // file_util::GetTempDir() directory. It deletes all the temporary files that
 | 
| +  // are in that directory before creating a new temporary file. It is a no-op
 | 
| +  // if we are already collecting data into a file.
 | 
| +  void StartNetLog();
 | 
| +
 | 
| +  // Stop collecting NetLog data into the temporary file. It is a no-op if we
 | 
| +  // are not collecting data into a file.
 | 
| +  void StopNetLog();
 | 
| +
 | 
| +  // Emails the temporary file if one exists.
 | 
| +  void SendNetLog();
 | 
| +
 | 
| +  // Helper function that runs on UI thread to send NetLog data via email.
 | 
| +  static void SendEmail(const FilePath& file_to_send);
 | 
| +
 | 
| +  // |lock_| protects access to |state_|.
 | 
| +  base::Lock lock_;
 | 
| +
 | 
| +  State state_;  // Current state of NetLogTempFile.
 | 
| +
 | 
| +  FilePath log_path_;  // FilePath to the temporary file.
 | 
| +
 | 
| +  // |net_log_logger_| watches the NetLog event stream, and sends all entries to
 | 
| +  // the temporary file created in StartNetLog().
 | 
| +  scoped_ptr<NetLogLogger> net_log_logger_;
 | 
| +
 | 
| +  DISALLOW_COPY_AND_ASSIGN(NetLogTempFile);
 | 
| +};
 | 
| +
 | 
| +#endif  // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_
 | 
| 
 |